#include <iostream>
#include <string>
using namespace std;
int findNum ()
{
int num;
cout<<"You have 10 chances to guess the number that is generated by this program."<<endl;
cout<<"All numbers generated are of positive integers"<<endl<<"Good Luck!!";
cout<<"Enter you guess ";
cin>>num;
return num;
}
string start (int guess)
{
int count = 1;
int num;
string result;
num = findNum ();
if (num == guess)
result = "You Win!!";
else {while (num != guess && count < 10)
{count = count + 1;
if (num == guess)
{result = "You Win!!";
return result;}
else if (num < guess)
{cout<<"Higher"<<endl;
num = findNum ();}
else if (num > guess)
{cout<<"Lower"<<endl;
num = findNum ();}
}
}
if (count == 10)
result = "You Lose!!";
else
result = "You Win!!";
return result;
}
int main ()
{
string result;
result = start (+rand());
cout<<result<<endl;
system ("pause");
return 0;
}
theUnspeakable 0 Newbie Poster
Lerner 582 Nearly a Posting Maven
theUnspeakable 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Lerner 582 Nearly a Posting Maven
theUnspeakable 0 Newbie Poster
Sky Diploma 571 Practically a Posting Shark
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.