![]() |
|
#1
|
|||
|
|||
What's wrong with my program?Hi. Our assignment was to write a program that finds the mean, median and mode of up to 50 integers entered by the user. My professor returned my assignment & said that my program is supposed to work for up to 50 integers, not just 50.
If anyone could please look at my program & help me figure out how I could correct, I would really appreciate it. Thank You, CPP / C++ / C Code:
|
|
#2
|
|||
|
|||
|
Quote:
Well, the idea is that you don't know beforehand how many items are going to be entered. So your program has to be able to tell when the end of the input data occurs. Three methods come to mind: 1. Use a special integer that will never be part of the data set, lets say -9999. Then when the user enters that number, break out of the input loop. I don't really like this, since it restricts the data set that can be valid numbers. 2. Break out of the loop if the program encounters End-of-File. This is the one to use if input comes from a file rather than user keyboard input. (End-of-File on Windows systems is usually ctrl-Z, but on Linux systems, and Windows systems running, say Cygwin and Bash, it's ctrl-D). 3. Break out of the loop if the program encounters a non-integer. This is the one that I like. You really should be testing user input for non-integers anyhow. Then your input loop looks like this: CPP / C++ / C Code:
Now, you only have to make sure that the rest of the program works as advertised with the actual number of data items. Regards, Dave Last edited by davekw7x : 23-Nov-2004 at 09:54.
|
|
#3
|
||||
|
||||
|
Quote:
1) Define MaxNum and initialize it to 0 2) Use a while loop instead of a for loop to input your values 3) For every value that gets entered, increment MaxNum 4) Change all your 50's to MaxNum That should do it. __________________
Age is unimportant -- except in cheese |
Recent GIDBlog
More photos on Flickr by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [TUTORIAL] Calling an external program in C (Linux) | dsmith | C Programming Language | 4 | 22-Apr-2005 13:30 |
| fltk-2.0 cvs | Plumb | FLTK Forum | 20 | 13-Nov-2004 07:10 |
| Something's wrong w/my program. | agentxx04 | C Programming Language | 1 | 07-Nov-2004 10:03 |
| Anyone can write a program code for this??? | chriskan76 | C Programming Language | 1 | 19-Oct-2004 20:25 |
| Need help with a C program (Long) | McFury | C Programming Language | 3 | 29-Apr-2004 20:06 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The