After watching the video, i wanted to share my own solution. It was different, but the same at some points. What do you think about that ? Also mine shows the total attempt number.
#include <iostream>
/*
RULES:
1)It is a two players game.
2)Player1 selects a random number.
3)Player2 needs to guess the number and the game will tell player2 whether the guess is too low/high.
4)The game will count the attempts of Player2.
*/
using namespace std;
int number = 0;
int guess = 0;
int numberOfGuess = 0;
int firstFunc(){
cout<<"Please pick a random number"<<endl;
cin >> number;
system("CLS"); // Cleans the screen. So that Player 2 won't see the number
}
int secondFunc(){
cout<<"Guess the number"<<endl;
cin >> guess;
if(number > guess){
cout<<"Your number is too low!"<<endl;
cout<<"Try again !!"<<endl;
numberOfGuess++;
secondFunc();
}
else if(guess > number){
cout<<"Your number is too high! SLOW DOWN"<<endl;
cout<<"Try again !!"<<endl;
numberOfGuess++;
secondFunc();
}
else{
cout<<"You've really made it!"<<endl;
cout<<"Only on "<<numberOfGuess + 1<< " try!!"<<endl;
cout<<"WELL DONE !"<<endl;
}
}
int main(){
firstFunc();
secondFunc();
return 0;
}