ここのすべては、関数 "tipConvert(tip)"を除いて私が望む方法で動作します。ヒント計算 - 数値を小数点に置き換えます
15などの数値を.15に変更してパーセント値の10進表記にする必要があります。
#include <stdio.h>
float tipConvert(int tip);
int main()
{
char value;
int intValue tip;
float bill, result;
intValue = 1;
while(intValue == 1)
{
printf("Would you like to calculate a tip: y or n?\n");
scanf("%s", &value);
if(value == 'y')
{
printf("Enter the bill amount:\n");
scanf("%f", &bill);
printf("Enter the tip amount as an integer:\n");
scanf("%i", &tip);
result = tipConvert(tip)*bill;
printf("Tip for %.2f is %.2f\n", bill,result);
}
else if(value == 'n')
{
printf("Thank you for using Tip Calculator.");
break;
}
else
printf("Please select y or n.\n");
}
return 0;
}
float tipConvert(int tip)
{
return tip/100;
}
質問のタイトルをあまり一般的ではないようにしてください。 「計算」とは何ですか? –
あなたはdividint 2 intsです。結果はintとして格納されます。したがって、除算の結果が0.xxのようなものである場合、ゼロに丸められます。したがって、tip/100.0を実行してください:これはうまくいくはずです。 –