![]() |
For Loops in this Code
What exactly does this program do? I don't get why the for loops would add one to the number the user types in if the number is less than the maximum number. I got this code from an ebook by the way, and I get compiler errors when I try to compile and run it in DevC++.
:
#include <iostream> |
the second for loop does not declare your variable i as an integer value.
:
#include <iostream> |
Thanks, I can compile the program now. But my question was really about the code. i equals 0, if it's less than MAX add 1? So if I typed in 22 it would become 23? Wouldn't that mess things up?
Also, when I run the program it closes immeadiately after I've entered the 3 numbers, so any number that it puts out, I can't see. How can I fix this? |
:
cin >> testScore[i];The 1 is being added strictly for presentation purposes. Arrays begin with element 0. Adding one to the number results in :
1. score from array 0:
0. score from array 0Don't post, "I got errors," or "It doesn't work." State the errors precisely and indicate the lines on which they occurred, if possible. If you get it running, and "It doesn't work," explain how it fails to meet your expectations. Have a look at the "How to Post a Question" thread, it's a sticky right at the top of this forum. |
Quote:
|
Look at your code again. The number you enter (testscore [i]) is not getting one added to it. The COUNTER (i) is getting one added to it.
Programs run until they complete, then terminate. If you run your program from the command line, then the window belongs to command.exe. When your program completes, command.exe will put out another prompt in the same window. Your output will still be showing. If you run your program in its own window (double-clicking its icon, say), then it will terminate and the window will close. If the IDE (if you have one) provides the window, then IT will stay open, but if it spawns a window specifically for that execution, the window will close. Note that the key word is "terminate". You may add an input statement to the end of your program so that it doesn't terminate until you provide it input. It'll sit there and wait for that, giving you plenty of time to look. You can use "cin.get ()." You will need to clear the input before "cin.get ()" in case your user has pounded in some extraneous stuff. You can use cin.sync (), although there is some controversy regarding its standardized applicability to a basic_istream, or you may use cin.ignore (). See your documentation. |
| All times are GMT -5. The time now is 2:03 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC