Feb 6, 2011 at 4:26pm UTC
this is a simple game to guess a die number:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(){
srand(static_cast<unsigned int>(time(0)));
int randomNumber=rand();
int die=(randomNumber%6)+1;
bool success;
success=true;
int playerturn;
do {
cout <<"guess your number";
cin >> playerturn;
if ( playerturn==die ){
success=true;
}
else { success!=true;
if (playerturn>die){
cout << "too high" << endl;
}
else {
cout << "too low" << endl;
}
}
while (success!=true);
cout << "this is the right number" << endl;
system("pause");
return 0;
}
there are errors, but I don't know what ?
Feb 6, 2011 at 4:31pm UTC
this line else { success != true ;
is your problem, what you're doing there is comparison, not assignment, success != true
compares success to true and returns a bool result, it doesnt set success to anything, you should be setting it to false success = false
also, please use code tags when posting code.
Last edited on Feb 6, 2011 at 4:31pm UTC
Feb 6, 2011 at 4:48pm UTC
thank you, but still I have error. the last brace is marked and written under it expected while. why ?
Feb 6, 2011 at 5:45pm UTC
actually add another } after your cout