473,386 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

c program help

Hello,
I need some help with a c program that is supposed to determine the kilometers per liter for 4 tanks of gasoline that a user fills in his/her car.

Here is what I have so far:
Expand|Select|Wrap|Line Numbers
  1.  for(i=1;i<=4;i++)
  2.  {
  3.   printf("/n/nEnter the number of kilometer for tank %d#: ",i);
  4.   scanf("%d", &km);
  5.   printf("Enter the number of liters used by tank %d#: ",i);
  6.   scanf("%f", <);
  7.   res = (float)km / lt;
  8.   printf("*** The kilometers per liter for tank %d# is %.1f", i, res);
  9.  }
  10.  getchar();
  11.  printf("Your overall average kilometers per liter for 4 tanks is /n/n");
  12.  printf("Thanks for using the Sears KPL calculator program.");
  13. }
  14.  
As it is now I get the error message: parse error after '<'.

Thanks in advance.
Mar 12 '08 #1
7 1304
manjuks
72
Hi,

scanf("%f", <); what is '>' . You have to give lt right?
remove < and give lt. it will work.

Thanks,
Manju
Mar 12 '08 #2
Thank you for your help

Expand|Select|Wrap|Line Numbers
  1. Full code removed
  2.  
Can you help me with the average?
Mar 13 '08 #3
oler1s
671 Expert 512MB
What's the problem with calculating the average?
Mar 14 '08 #4
What's the problem with calculating the average?
For some reason Dev-C++ is displaying the average part of the program, so I can't tell if it is working properly. Can you tell me if what I have is correct or what I have to fix? Thanks.

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. int main()
  4. {
  5.  int km, i;
  6.  float res, lt, sum, avg;
  7.  
  8.  printf("Welcome to the Sears kilometers per liter calculator.\n\n");
  9.  
  10.  for(i=1;i<=4;i++)
  11.  {
  12.   printf("\n\nEnter the number of kilometer for tank %d#: ",i);
  13.   scanf("%d", &km);
  14.   printf("Enter the number of liters used by tank %d#: ",i);
  15.   scanf("%f", &lt);
  16.   res = (float)km / lt;
  17.   printf("*** The kilometers per liter for tank %d# is %.1f", i, res);
  18.  }
  19.  sum = 0;
  20.  sum = sum + res;
  21.  avg = sum/4;
  22.  printf("Your overall average kilometers per liter for 4 tanks is %.1f", avg);
  23.  printf("\n\nThanks for using the Sears KPL calculator program.");
  24.  getchar();
  25. }
  26.  
Mar 14 '08 #5
whodgson
542 512MB
The closing for loop brace seems to need to be relocated 2 lines down....i think?
Mar 14 '08 #6
Nanite
1
All your are doing is is dividing result of the last tank by 4.


To get the average:
Initialize sum to zero before the for loop.
You want to add res to sum each time res is calculated. So you what to do that inside the for loop after the calculation of res.
After the loop divide by the total number of tanks gets you the average.

Like this.

Expand|Select|Wrap|Line Numbers
  1. Edit: removed code since I realized it is a against posting guidelines. I'll send you the code in a PM sleep.
  2.  
Note: "sum += res;" does the same thing as "sum = sum + res;" it's just preference. Also I added NUM_TANKS because it's good practice to create a #define or variable for any common value appearing multiple times in you code such as the number of tanks, so if you ever need to change it you only need to go to one spot. No big deal since it's only used twice, just for good practice.
Mar 14 '08 #7
Many thanks for all the help you guys have given me.
Mar 14 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: anuradha.k.r | last post by:
hi, i am writing a socket program in python,both client side and server side.I've written the client side which is working perfectly fine(checked it against server program written in C).but as for...
2
by: stanlo | last post by:
Hallo to everyone, i am just begining to learn c++ even though i did pascal when i studied mathematics in the univesity.i just took on my self a project which writing a c++ program which does...
7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
1
by: Willing 2 Learn | last post by:
Below is a program I did to recognize a Finite State Automata for ASCII (J+H)*. I got that one working but im having trouble getting the NFA program to work. I really desperately need help! My...
66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
12
by: asif929 | last post by:
I am trying to write a program which creates four triangles. The program begins with prompting a user " Enter the size of triangles", number from 1 to N is the size of four triangles For Example if...
21
by: asif929 | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to...
0
by: ashishbathini | last post by:
Hi guys here is my problem ... this is the source code I Have , honestly I hav no idea how it works bcos its too complicated for me .... but my problem is ... i hav a freq comonent in it .......
9
by: C#_Help_needed | last post by:
I need help with the following question. THANKS :) Write a program in c# that takes in a directory as a command line parameter, and returns the longest repeated phrase in ALL text files in that...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.