-
help with float
Howdy. I need a little help with float.
Code:
/*******************************************************************************
* Name: Trip.c
* Assignment: LAB 2
* Date Written: 10/11/2007
* Course: CS133
* Purpose: Calculate usefull info for a car trip
* Sources:
*******************************************************************************/
#include <stdio.h>
main()
{
printf("Welcome to the Trip Planner! So you are ready to take a trip?"
"Let me help you plan for your fuels costs."
"==============================================================================="
"Please provide answers to the prompts below and I will"
"display a summary for you when I have computed the results."
"===============================================================================\n")
float MPG, cost, miles, gallons, Tcost;
printf("Please input your car's average miles per gallon >> ");
scanf("%f", &MPG);
printf("Please tell me the going rate for fuel (per gallon) >> $ ");
scanf("%f", &cost);
printf("Please tell me how many miles you plan to travel >> ");
scanf("%f", &miles);
gallons= miles / MPG;
Tcost= gallons * cost;
printf("You will need to purchase" %f\n, gallons "gallons of fuel");
printf("The approximate cost of fuel for your trip is: %f\n", Tcost);
printf("Thank you, please drive safely and have a nice trip!");
return 0;
}
Thats the main chuck of the source code. According to the compiler, none of my objects listed under fload are declared. Just not really sure what to do to fix all this. I'm very new at all of this!
Thanks in advanced,
Kevin
-
Code:
gallons= miles / MPG;
Tcost= gallons * cost;
what is the whole code?
-
Hai friend you had given MPH in the place of MPG in the scanf so it will give the compile error...
-
Quote:
Originally Posted by
robwhit
Code:
gallons= miles / MPG;
Tcost= gallons * cost;
what is the whole code?
That was the only chuck yelling at me. But I just put in the whole code.
Lol, good catch sreeramu. Thanks. But with those 2; and that correction, I still get the exact same errors. If you want, I can post the errors that it's giving me.
And FYI, I know that the line: printf("You will need to purchase" %f\n, gallons "gallons of fuel");
is way wrong. I'm trying to have the program input the amout of gallons you need to buy in the middle of the printf, and I have no idea. But thats a (somewhat) different question.
-
Quote:
Originally Posted by
thor4life
Code:
/
main()
{
printf("........") /* <---missing semicolon */
float MPG, cost, miles, gallons, Tcost;
T..what to do...
Some compilers require that all data declarations in a block must appear before executable statements.
All compilers require semicolons at the end of statements.
(Why not keep the printf stuff short and simple until you verify the functionality? Dress it up later. Just a thought.)
D.
-
Oh, trust me, I'd like to, but this is for an online class, and the teacher is out for a couple days.
The missing ; after that 1st long printf solved the float issue. Now I have to figure out how to make:
Code:
printf("You will need to purchase" %f\n, gallons "gallons of fuel");
work. Any ideas?
-
Code:
printf("You will need to purchase %f gallons of fuel\n" , gallons);
-
Code:
#include <stdio.h>
int main()
{
printf("Welcome to the Trip Planner! So you are ready to take a trip?"
"Let me help you plan for your fuels costs."
"==============================================================================="
"Please provide answers to the prompts below and I will"
"display a summary for you when I have computed the results."
"===============================================================================\n")
{
float MPG, cost, miles, gallons, Tcost;
printf("Please input your car's average miles per gallon >> ");
scanf("%f", &MPG);
printf("Please tell me the going rate for fuel (per gallon) >> $ ");
scanf("%f", &cost);
printf("Please tell me how many miles you plan to travel >> ");
scanf("%f", &miles);
gallons= miles / MPG;
Tcost= gallons * cost;
printf("You will need to purchase %f gallons of fuel\n", gallons);
printf("The approximate cost of fuel for your trip is: %f\n", Tcost);
printf("Thank you, please drive safely and have a nice trip!");
}
return 0;
}