![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Loop just doesn't want to stop looping when I tell it to...Obviously the problem is me and not the loop.
But here's a watered down version of my code with the cout strings changed so there's no confusion. CPP / C++ / C Code:
also.....the second "else if" i tried "else" but then i get the error - " expected `;' before '{' token " apparently the "int a" isn't changing its value to 6 when the if statement is being used. say i enter "y" or "n", it will give me the respective cout, but then it will say "your answer is invalid" and keep looping. |
|||
|
#2
|
||||
|
||||
Re: Loop just doesn't want to stop looping when I tell it to...Hint: In C/C++, you test for equality with the "==" operator; "=" represents assignment.
Best regards, Lucian Edit: If you copied some of the code from somewhere else, I recommend reading up on the structure of the for loop. __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#3
|
|||
|
|||
Re: Loop just doesn't want to stop looping when I tell it to...one more thing.
the "cout << a;" that i have there doesn't "cout" when i run the program. and that's the only reason i put it there, to see if it worked or not. which is what helped me determine it must be something with the value of "int a". |
|
#4
|
||||
|
||||
Re: Loop just doesn't want to stop looping when I tell it to...Did you input a value when "cin" asked for one, so the program flow could continue? If not, read up on what "cin" does.
Btw, I am going to sleep __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#5
|
|||
|
|||
Re: Loop just doesn't want to stop looping when I tell it to...Quote:
okay so i edited this part. CPP / C++ / C Code:
and it still loops. |
|
#6
|
|||
|
|||
Re: Loop just doesn't want to stop looping when I tell it to...Quote:
the line: CPP / C++ / C Code:
the sentence says "A yes or no answer is needed. Y/N:" and when i enter y or n, 'x' gets assigned "y" or "n". which is then what i have the if and else statements for. so depending on what value is given to 'x', the program will output a different sentence...and then re-assign 'a' to 6, so the loop stops looping. it's only supposed to loop if 'x' was assigned something other then "y" or "n". but it's looping regardless. and not cout'ing 'a' when i ask it to. thanks for the help, but im pretty sure the problem isn't the "cin >> x;" line. |
|
#7
|
||||
|
||||
Re: Loop just doesn't want to stop looping when I tell it to...Although you changed a=5 to a==5 in the else if condition, the loop's condition has the same problem.
(unless you've fixed it since then, it would probably be a good idea to post your latest working code in your next post) __________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
|
#8
|
|||
|
|||
Re: Loop just doesn't want to stop looping when I tell it to...this is what i have so far:
CPP / C++ / C Code:
|
|
#9
|
|||
|
|||
Re: Loop just doesn't want to stop looping when I tell it to...Your problem is caused by a mistake in the condition test in this statement:
CPP / C++ / C Code:
|
|
#10
|
|||
|
|||
Re: Loop just doesn't want to stop looping when I tell it to...I'm wondering why you're using a string for one character?
Also, you might run into errors because your (posted) code doesn't prepare for the possibility of a 'Y' or 'N'. I suggest using toupper (if you're allowed to) or alternatively using the || (or) CPP / C++ / C Code:
also, check as to why you want your loop to break after an invalid statement and not after 'no' or 'yes'.. unless you wanted the loop to stop after something other than no or yes was enterd.. but if that's the case you should state it. |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Classic recursion game of 8 Queens errors | BKizzle77 | Java Forum | 11 | 11-Aug-2008 01:35 |
| breaking an infinite loop through stdin | pisuke | C Programming Language | 9 | 03-Jul-2007 21:19 |
| Text-Based Roulette Game | mfm1983 | C++ Forum | 5 | 29-Nov-2006 13:20 |
| coding a sentinel controlled loop | tommy69 | C++ Forum | 2 | 10-Mar-2004 15:52 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The