【发布时间】:2014-11-16 19:17:36
【问题描述】:
所以,明天晚上我的在线 C 编程课程的作业要交了,我现在的编码有些问题。我已经把代码带给了我的老师,但她似乎不明白她是花钱教我的,而不是告诉我我的代码有问题。如果有人可以查看代码并帮助我修复它,我将不胜感激。代码位于下方。调用 printtripSummary 时出现错误的位置在 main 中。
#include <stdio.h>
void welcomeMessage();
void askuserForInput();
void printtripSummary(float avgMiles, float minCost, float maxCost, float travelMiles);
int main()
{
/* Call the functions */
welcomeMessage();
askuserForInput();
printtripSummary();
printf("\nThank you, please drive safely and have a nice trip!\n");
return 0;
}
void welcomeMessage()
{
printf("Welcome to the Trip Planner!\n");
printf("So you are ready to take a trip? Let me help you plan for\n");
printf("your fuels costs and required stops to fill up your tank.\n");
printf("============================================================\n");
printf("Please provide answers to the prompts below and I will\n");
printf("display a summary for you when I have computed the results.\n");
printf("============================================================\n");
}
void askuserForInput()
{
float avgMiles, minCost, maxCost, travelMiles;
do{
printf("Please input your car's average miles per gallon (enter 0 to quit)>> ");
scanf_s("%f", &avgMiles);
if (avgMiles == 0)
break;
printf("Please tell me the range of fuel costs you expect to pay (per gallon>>)\n");
printf("The lowest per gallon cost of fuel is>> ");
scanf_s("%f", &minCost);
printf("The highest per gallon cost of fuel is>> ");
scanf_s("%f", &maxCost);
printf("Please tell me how many miles you plan to travel>> ");
scanf_s("%f", &travelMiles);
printtripSummary(avgMiles, minCost, maxCost, travelMiles);
} while (avgMiles != 0);
}
void printtripSummary(float avgMiles, float minCost, float maxCost, float travelMiles)
{
float avgGal, mingasPrice, maxgasPrice;
do{
avgGal = travelMiles / avgMiles;
mingasPrice = avgGal * minCost;
maxgasPrice = avgGal * maxCost;
printf("You will be required to purchase %.2f gallons of fuel.\n", avgGal);
printf("The price will range between %2f and $%.2f.\n", mingasPrice, maxgasPrice);
} while (avgMiles != 0);
}
【问题讨论】:
-
如果我可以问,这个错误是如何让自己知道的?
-
查看
printtripSummary函数的原型(和定义),然后查看您对该函数的调用。 -
在
main中调用函数printtripSummary你必须给parameters!您还可以在askuserForInput中调用函数,因此您只需在 main out 中注释函数调用 -
@JoachimPileborg 哦 :-)
-
“她花钱是为了教我,而不是告诉我我的代码有问题”。也许她认为这个明显的错误信息是你从解决中学到的东西,而不是她只是告诉你。