So, I have to write a program from a random guessing game. The program needs to ask the player to guess a number between 1-100. At least one function must be used. It needs to tell the player if they are too low/high, ask them to try again, or if they guess it, ask them to play again.
I have a few errors that I can not figure out.
44: error: ‘int winlose’ redeclared as different kind of symbol 9: error: previous declaration of ‘int winlose(int)’ 44: error: ‘g’ was not declared in this scope
Code
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int winlose(int);
int main()
{
int g, n, x;
while (x!=0)
{
do
{
srand(time(NULL));
n = 1 + rand()%100;
cout<<"Welcome to the guessing game. I have a number between 1-100.
Can you guess it?"<<endl;
cout<<"Please enter your guess"<<endl;
cin>>g;
winlose(g);
} while (n!=0);
cout<<"Play again? Enter 0 for no, any other number for yes."<<endl;
cin>>x;
}
return 0;
}
int winlose(g)
{
if (g<n)
{
cout<<"Your guess is too low. Try again."<<endl;
cin>>g;
}
else if (g>n)
{
cout<<"Your guess is too high. Try again."<<endl;
cin>>g;
}
else (g=n)
{
cout<<"Congrats! You win. The number was "<<n<<endl;
n=0;
}
return g;
return n;
}