![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Programmer
Join Date: Sep 2005
Location: Oopland
Posts: 36
Rep Power: 0
![]() |
Help with some source code
Ugh, this is almost embarassing, first time posting source code. ._.
I have an error with a program I constructed. It compiles fine, I just can't seem to locate the problem. The program is suppose to continue to guess random numbers and compare it to a number that the user inputted and continue until it guesses it... Buuut it stops after the first try. ;.; Quote:
-Me Edit: I think it might be my loop, considering switching to a single while loop versus the do. Any invoice would be helpful, as I can't test it at the moment, I have to go run some errands. Double edit: Ugh, I just realized the problem. Will attempt to fix it asap. 8) |
|
|
|
|
|
|
#2 | |
|
Programmer
Join Date: Sep 2005
Location: Oopland
Posts: 36
Rep Power: 0
![]() |
Okay, I really have to get going, but this is the new source. Now It won't cout the guess and ends the loop. Any help on my half-assed new source would be appreciated! 8)
Quote:
Ooookay, I'm sorry, just delete this. I fixed it. I'm a stubborn little boy. ._. |
|
|
|
|
|
|
#3 |
|
Programming Guru
![]() |
[php]#include <iostream>
#include <cstdlib> #include <ctime> using namespace std; int main(int argc, char *argv[]) { srand(time(NULL)); int tries = 0, theNumber = -1, theGuesser = -1; cout << "\tWelcome to the Guess My Number game; White-hat` edition!" << endl << endl; while(theNumber < 1 || theNumber > 100) { cout << "Please enter your number, so the computer may guess it: "; cin >> theNumber; } while(theNumber != theGuesser) { theGuesser = (rand() % 100) + 1; tries++; } cout << "\nLooks like he guessed it in " << tries << " tries! Uh oes!" << endl << endl; return 0; }[/php]
__________________
|
|
|
|
|
|
#4 | |
|
Programmer
Join Date: Sep 2005
Location: Oopland
Posts: 36
Rep Power: 0
![]() |
Oh, I didn't see your code. I'mma toy with that soon as I get some time. I ended up with this:
Quote:
|
|
|
|
|
|
|
#5 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
You're only real problem was this:
while (theGuesser == theNumber) Oh, and please use [code] tags, not [quote] tags next time. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|