#include<iostream>
#include<cstdlib>
using namespace std;
int menu();
void play();
int main()
{
int choice,operate,magic;
do
{
operate=menu();
switch (operate)
{
case 1:play();break;
case 2:break;
case 3:cout<<"Goodbye!"<<endl;break;
}
}while (operate != 3);
return 0;
}
// menu fuction...
int menu()
{
int choice;
cout<<"1.Get a new magic number."<<endl;
cout<<"2.Play now."<<endl;
cout<<"3.Quit."<<endl;
cout<<"Enter your choice:";
cin>>choice;
return choice;
}
//play fuction...
void play()
{
int i,magic,guess;
magic = rand();
magic = magic%10;
for (i=1;i<=3;i++)
{
cout<<"Guess :";
cin>>guess;
if (guess==magic)
{cout<<"**RIGHT**"<<endl<<endl<<endl;break;}
else if (guess>magic)
cout<<"It's too high."<<endl;
else cout<<"It's too low."<<endl;
}
if (i==4)
{cout<<endl<<"**Your chance have losted out.**"<<endl<<"End game this time.";
cout<<endl<<"The magicNum is "<<magic;
cout<<endl<<"Come on again?"<<endl<<endl<<endl;}
}