![]() |
|
#1
|
|||
|
|||
Program using a for loopI cant figure this out. I have tried working on this for several hours with no luck. I have this so far and dont know if I am even on the right track. Here is the code I wrote so far:
CPP / C++ / C Code:
This program asks the user how many days to enter the temperature of any certain day. Use a for loop that allows the user to enter the number of temperatures that the user has specified. Compute and display the average temp at end of file. Any help would greatly be appreciated. I am having trouble because the for loop. Count=0; count=??? This should be equal to whatever the user puts in for the amount of days. |
|
#2
|
||||
|
||||
|
Hi Tommy. When you post code, it really helps if you enclose it between [c] and [/c]. It makes it much easier to read as you can see.
You probably want your for statement to look more like: CPP / C++ / C Code:
I give a break down of the elements of a for statement in this post. Also, I think that you would want your total to be a float and that you should total your tempatures in your for statement like this: CPP / C++ / C Code:
and then when you exit your for loop you could print the average with CPP / C++ / C Code:
|
|
#3
|
|||
|
|||
almost thereCPP / C++ / C Code:
|
|
#4
|
||||
|
||||
|
The problem is scanf().
Define a character buffer called buf[12]; and change each scanf()s to: CPP / C++ / C Code:
scanf() is leaving crap in the input buffer. Also note the change in the %f |
Recent GIDBlog
Writing a book by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C program to convert NFA to DFA | ayoub | C Programming Language | 11 | 14-Sep-2007 15:51 |
| Please Help, problems writing newbie c program | soulfly | C Programming Language | 14 | 04-Mar-2004 16:16 |
| compiling a program within another (C++) | Siphiro | C++ Forum | 5 | 06-Feb-2004 16:35 |
| error during program | rjd72285 | C++ Forum | 0 | 11-Nov-2003 19:49 |
| one program access another? | dgoulston | C++ Forum | 1 | 07-Oct-2003 12:26 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The