![]() |
|
#1
|
|||
|
|||
Help with an Array problemI'm doing this assignment. Just so it gets explain thoroughly, here's the assignment what I've coded: Write a C++ program to input ten integer numbers into an array named fmax and determine the maximum value entered. Your program should contain only one loop and the maximum should be determined as array element values are being input. (Hint: Set the maximum equal to the first array element, which should be input before the loop used to input the remaining array values.)
CPP / C++ / C Code:
Code:
|
|
#2
|
|||
|
|||
Re: Help with an Array problemQuote:
CPP / C++ / C Code:
That is the entire main() function. Open brace - function - close brace. Look for examples in your book or other course materials. They don't put braces around groups of statements just for the heck of it! In your program: Put an open brace '{' on the next line after main() Put a close brace '}' on the next line after return 0; No other braces are needed in your main() function. The function findMax is properly braced, but you may still have an error or two to fix. Oh, by the way: no one was born knowing this stuff. Keep plugging! If you get messages or other behavior that you don't understand, ask again. Thanks for posting. Regards, Dave |
|
#3
|
|||
|
|||
Re: Help with an Array problemOkay I fixed the program and it runs but I get this:
CPP / C++ / C Code:
Code:
|
|
#4
|
|||
|
|||
Re: Help with an Array problemQuote:
What part of your program expects the user to enter 10 numbers? You ask for a number (one time), then try to store it in an undefined memory location. Why do I say undefined? You haven't given a value to i, and then you try to store something in nums[i]. What do you expect to happen? Read your course materials. If you want to do something 10 times, one way is to make a loop that is traversed 10 times. If you want to get 10 numbers from the user and store them into array elements nums[0], nums[1], ... nums[9] you would make a loop that lets i go over the range [ 0, 9 ] and, each time through the loop, get a number from the user and store it in nums[i]. Something like that. Surely your course materials have examples of for(){}loops. Right? Regards, Dave |
|
#5
|
|||
|
|||
Re: Help with an Array problemI got the program to loop but it does this:
CPP / C++ / C Code:
Code:
Last edited by admin : 05-Apr-2007 at 23:39.
Reason: Please insert your C code between [cpp] & [/cpp] tags
|
|
#6
|
|||
|
|||
Re: Help with an Array problemQuote:
Code:
The program ran to completion before giving me a chance to enter anything. The program doesn't have any input statements, so how could it possibly work? It is pretty hard to help unless you post the program that you are actually running. A way to get user input is with cin: CPP / C++ / C Code:
Aren't there any examples in your book or other course materials? Quote:
If you really want to put the values into an array you can do it in the same loop, but I don't see the point. Bottom line: if your assignment requires that the entire program must have only one loop, you can't have one loop to get user input and another loop to find the maximum of the input values. Quote:
Then I respectfully request that you look at examples in your book or other course materials. What part do you not understand? You have done the logic for finding max. Code:
Regards, Dave Last edited by davekw7x : 06-Apr-2007 at 08:34.
|
Recent GIDBlog
Meeting the populace by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem with filling a char array in a windows GUI app. | ryver | C++ Forum | 1 | 13-Aug-2006 08:22 |
| Need help deleting the last element in the array | headphone69 | C++ Forum | 2 | 15-Mar-2006 19:31 |
| problem modifying an array of char in a function | ronin | C Programming Language | 10 | 28-Mar-2005 18:15 |
| template comiling problems - need expert debugger! | crq | C++ Forum | 1 | 01-Feb-2005 21:26 |
| problem reading to a dynamic array | noamfrie | C Programming Language | 9 | 02-Jan-2005 18:35 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The