#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void guessGame();
bool isCorrect(int, int);
int main(){
srand (time (0));
guessGame();
return 0;
}
void guessGame(){
int answer;
int guess;
char response;
do{
answer = 1 + rand() % 10; // make constant random value from 1 to 100
cout << "Guess number between 1 and 10" <<endl;
cin >> guess;
while( !isCorrect(guess, answer)) // as long as the return value is false, continue
cin >> guess; // condition itself calls funtion
cout << "\n Congrat!! wanna play new guess?" << endl;
cout << " \"y\"to start \"n\" to end" << endl;
cin >> response;
} while (response == 'y');
}
//isCorrect returns true if the guess is right
//if g does not equal a, displays hint
bool isCorrect(int g, int a){
if (g == a){
return true;
}
if (g < a){
cout << "Too low.. Try again" << endl;
}
if (g > a){
cout << "Too high.. Try again" << endl;
}
return false;
}
/*This semester I take c++ and JAVA class...learning coding by English is not easy...
it has been so long time to post my coding...
Actually I practiced some materials of professor making the copy of them but didn't post..don't know why
And definitely JAVA is complicated!!!!!
I got stuck doing assignment, found myself too stupid to go further and wend back to the very first meterials of class
I hope I can make improvement during left holiday....
no "wait and see" but "do it and see"....... */
#include <cstdlib>
#include <ctime>
using namespace std;
void guessGame();
bool isCorrect(int, int);
int main(){
srand (time (0));
guessGame();
return 0;
}
void guessGame(){
int answer;
int guess;
char response;
do{
answer = 1 + rand() % 10; // make constant random value from 1 to 100
cout << "Guess number between 1 and 10" <<endl;
cin >> guess;
while( !isCorrect(guess, answer)) // as long as the return value is false, continue
cin >> guess; // condition itself calls funtion
cout << "\n Congrat!! wanna play new guess?" << endl;
cout << " \"y\"to start \"n\" to end" << endl;
cin >> response;
} while (response == 'y');
}
//isCorrect returns true if the guess is right
//if g does not equal a, displays hint
bool isCorrect(int g, int a){
if (g == a){
return true;
}
if (g < a){
cout << "Too low.. Try again" << endl;
}
if (g > a){
cout << "Too high.. Try again" << endl;
}
return false;
}
/*This semester I take c++ and JAVA class...learning coding by English is not easy...
it has been so long time to post my coding...
Actually I practiced some materials of professor making the copy of them but didn't post..don't know why
And definitely JAVA is complicated!!!!!
I got stuck doing assignment, found myself too stupid to go further and wend back to the very first meterials of class
I hope I can make improvement during left holiday....
no "wait and see" but "do it and see"....... */
댓글
댓글 쓰기