Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thuytt - test1 #333

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions AdvProg_L1-GuessIt/guessit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ using namespace std;
***/
int generateRandomNumber() {
// TODO: Return the random number in range 1 to 100
return 100;
int randomNumber = rand() % 100 + 1;
return randomNumber;
}


Expand All @@ -26,8 +27,9 @@ int generateRandomNumber() {
***/
int getPlayerGuess() {
// TODO: Ask the player guest and return the player's number

return 1;
cout << endl << "Enter your guess: ";
int guess; cin >> guess;
return guess;
}


Expand All @@ -46,6 +48,9 @@ string getAnswer(int number, int randomNumber) {
If number is equal randomNumber, the answer is "Congratulation! You win."
***/
string answer;
if(number>randomNumber) answer="Your number is higher.";
else if (number<randomNumber) answer= "Your number is lower.";
else answer ="Congratulation! You win.";

return answer;
}
Expand All @@ -59,8 +64,10 @@ string getAnswer(int number, int randomNumber) {
***/
bool checkSuccess(string answer) {
// TODO: return the result after checking that player guessed right or wrong

return true;
bool success=false;
if(answer=="Congratulation! You win.") success=true;
return success;
// return true;
}


Expand All @@ -73,7 +80,8 @@ bool checkSuccess(string answer) {
bool checkContinuePlaying(char isContinued) {
// TODO: return result after checking player continue playing or not
bool result = false;

cout<<"continue playing or not? Y or N ?";
if(isContinued=='Y'||isContinued=='y') result=true;
return result;
}

Expand All @@ -87,7 +95,7 @@ bool checkContinuePlaying(char isContinued) {
char getPlayerOpinion() {
// TODO: Ask the player about continue playing and return the player's choice
char isContinued;

cin >> isContinued;
return isContinued;
}

Expand All @@ -112,4 +120,4 @@ int run() {
isContinued = getPlayerOpinion();
} while (checkContinuePlaying(isContinued));
return 0;
}
}
Loading