这是我第一次编程,我迷路了。我试图做这个数学运算,但它不断出错,我不确定问题出在哪里。此外,我不知道如何使所有数字输出到两位小数。请帮忙。这是我迄今为止所提出的。数学运算?
int main(void) {
int distance, time, speed, meters, mts_per_mile, sec_per_mile, mts, mps;
csis = fopen("csis.txt", "w");
distance = 425.5;
time = 7.5;
speed = distance/time;
mts_per_mile = 1600;
sec_per_mile = 3600;
mts = distance * mts_per_mile;
mps = mts/sec_per_mile;
printf("The car going %d miles in %d hours is going at a speed of %d mph.\n", distance, time, speed);
fprintf("The car going %d miles in %d hours is going at a speed of %d mph.\n", distance, time, speed);
printf("The car has traveled %d meters total, at a rate of %d meters per second.", mts, mps);
fprintf("The car has traveled %d meters total, at a rate of %d meters per second.", mts, mps);
fclose(csis);
return 0;
}
那么,而不是使用'int'变量使用'double'或'float'。这将解决您的问题。 – ameyCU
'int'代表[integer](https://simple.wikipedia.org/wiki/Integer)。 –
你打电话给'fprintf'错误 –