「1.#R」を印刷する別の浮動小数点出力の問題があります。繰り返しの値に絞り込んだので、値を小数点以下 2 桁に丸める方法を教えてください。 %.2f")。これが私のコードです:
#include <stdio.h>
#include <stdlib.h>
void tax_deduction( float *total)
{
float taxpercent = 1.20;
float nationalInsurance = 1.175;
*total = *total - 9000;
*total = *total / taxpercent;
*total = *total / nationalInsurance;
*total = *total + 9000;
}
void hourly_rate(float *rate)
{
int weeks = 52;
float hours = 37.5;
*rate = *rate /(float)weeks;
*rate = *rate /hours;
}
int main()
{
float wages;
float hours = wages;
printf("Please enter your wage: \n");
scanf("%f",&wages);
if(wages > 9000){
tax_deduction(&wages);
}
hourly_rate(&hours);
printf("wages after tax and NI: %.2f\n", wages);
printf("wages per month: %.2f\n", wages / 12);
printf("hourly rate: %.2f\n", hours);
return 0;
}
下部にprintf("hourly rate: %.2f\n", (wages/52)/37/5);のようにコーディングすると、hourly_rate 関数を実行した後の表示方法に問題があります。それは機能しますが、それは私がコーディングしたい方法ではありません。
なぜこれが正しく機能しないのか、誰でも考えられますか?