Write your question here.I'm a noob, I wrote this code to play a little game with random numbers, but the code doesn't run properly, I want computer to be able to tell the player if player guess is low,high or correct, and I need the game to keep promoting the player to input an answer til the player wins
#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
usingnamespace std;
int coinflip(int x, int y){ // function that // compares the // // players guess to // computer random number
return rand() % (y - x);
}
bool playgame (int gameon){ // function that // allows the player to either // play or quit game
if (gameon== 1){
returntrue;
returnfalse;
}
}
int main(){
srand(time(NULL));
int userinput;
string userinput2;
int userinput3;
int x=1;
int y=7;
cout <<"welcome to the game" << endl<<endl<<endl;
cout << "to play press 1 " << endl;
cout << " to exit press 2 " << endl;
cin >> userinput ;
if (userinput!=1){
cout << " thanks for playing " <<endl; return 0;
}
if (playgame(userinput) == true){
cout << "computer is thinking of a number, to guess what number it is enter < yes>" << endl;
cin >> userinput2;
if (userinput2 == "yes"){
cout << " guess the number computer is thinking and enter it below, numbers ranging from 1-6 " << endl;
cin >> userinput3 ;
}
if (userinput3==coinflip(x,y)){
cout << " congrats you win" << endl;}
if (userinput3<coinflip(x,y)){
cout << " too low " << endl;}
if (userinput3>coinflip(x,y)){
cout << " too high " << endl;}
}
}
and as for the other problem the simple structure of that would be:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
while (/*players guess isn't equal to number*/)
{
if (/*players number < computers number*/)
{
cout << "The number is larger than your guess" << endl;
}
elseif (/*players number > computers number*/)
{
cout << "The number is smaller than your guess" << endl;
}
elseif (/*players number == computers number*/)
{
break;
}
}
cout << "YOU WIN" << endl;