Whenever a number is given as an input, it always say too low even if I put negative value while the less and max random number is 1-100
. I don't really understand why it is not working.
#include<iostream>
Is there a problem in here?
#include<cstdlib>
#include<time.h>
above
using namespace std;
void again();
void play_game();
void again()
{
int schoice;
while(true)
{
cout<<"\n\nYou want to play again?\n\n";
cout<<"1) Play Again"<<endl;
cout<<"0) Exit\n\n";
cout<<"Input answer:";
cin>>schoice;
if(schoice == 1)
{
play_game();
}
else if(schoice == 0)
{
cout<<"\nOh ok see ya!\n\n";
break;
}
}
}
void play_game()
{
Or the problem is in here?
srand(time(0));
int RanNum;
RanNum = rand() % 100 + 1;
This part I don't really understand (above)
cout<<"\n\n*The game is being played*\n\n"<<endl;
cout<<"Guess the number between 1 to 100\n"<<endl;
while(true)
{
cout<<"Input number:";
int maxNum = 100;
int leastNum = 1;
int guess;
cin>>guess;
if(guess < leastNum || guess > maxNum)
{
cout<<"It must be higher or equal than"<<" "<<leastNum<<endl<<"and it must not exceed"<<" "<<maxNum<<endl;
}
else if(guess < RanNum)
{
cout<<"\nYour number is LOW\n"<<endl;
}
else if(guess > RanNum)
{
cout<<"\nYour number is HIGH\n"<<endl;
}
else
{
cout<<"\nYour correct!";
again();
break;
}
}
}
int main()
{
int choice;
cout<<"Want to play the game?\n\n"<<endl;
cout<<"Type 1 if want to play"<<endl<<"Type 0 if not\n\n"<<endl;
cout<<"Input here:";
cin>>choice;
switch(choice)
{
case 1 :
play_game();
break;
case 0 :
cout<<"\nOh ok see ya!\n\n";
break;
default :
cout<<"\n\nThe choices are\n\n1 or 0 \n\nplease try again\n\n";
break;
}
return 0;
}