Sep 14, 2011 at 11:12pm UTC
i need help with my first project in c++. I think i have the content bu yet i can't find where to put a close brace }....please help me go over my code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int guess;
int upperBound;
int lowerBound;
int range;
unsigned int seed = static_cast <unsigned int >(time(0));
srand(seed);
char c;
bool done = false ;
do {
bool found = false ;
upperBound = 101;
lowerBound = 1;
do {
range = upperBound - lowerBound;
guess = lowerBound = (rand() % (range));
if (range > 0)
{
char response;
cout << "Hey..is this your number? (lhy) " << guess << endl;
cin >> response;
switch (response) {
case 'l' :
case 'L' :
cout << "Too low" << endl;
lowerBound = guess + 1;
break ;
case 'h' :
case 'H' :
cout << "Too high" << endl;
upperBound= guess - 1;
break ;
case 'y' :
case 'Y' :
cout << "Yes!" << endl;
found = true ;
break ;
default :
cout << " Does not compute" << endl;
break ;
};
}
else {
cout << "Your number must be: " << lowerBound << endl;
found = true ;
}
bool done = false ;
do {
cout << "do you want to play again? (y/n)" << endl;
cin >> c;
if (( c == 'n' ) || (c =='N' ))
{done = true ;
cout << "Thanks for playing" << endl;
}
else {
cout << " Great pick another number!" << endl;
}
} while (!found);
cout << "Press any key and <Enter> to continue..." << endl;
char c;
cin >> c;
return 0;
}
[code]
[/code]
Last edited on Sep 15, 2011 at 1:59am UTC
Sep 14, 2011 at 11:18pm UTC
One, please put your code in code tags. Click the <> symbol on the right or do it manually by adding the tags yourself. I can't see line numbers or indentation, but it looks like your first do loop is missing a closing brace, and most of them don't even have conditions. Lastly, what's so hard about finding a missing closing brace? Your compiler should tell you where the problem is, I think you could've figured this one out on your own :/
Sep 15, 2011 at 8:11pm UTC
Stewbond, try not to give out so much code, it doesn't help the person in the end!
Last edited on Sep 15, 2011 at 8:11pm UTC
Sep 17, 2011 at 3:26am UTC
I am trying to write the same program,
but this code doesn't seem to work right and I am having the same problem.
When you enter h l or y it just ends the game,
please help!!
Sep 17, 2011 at 6:58pm UTC
Please show us your code, thanks.