Guessing_Game.html
#include<iostream>
#include<time.h>
#include<dos.h>
#include<stdlib.h>
using namespace std;
int input(){
int n;
cout<<"Enter a value -> ";
cin>>n;
return n;
}
int random(){
srand(time(NULL));
return (rand()%101);
}
int main(){
int n,r,i,j;
r= random();
for(i=0;i<5;i++){
n=input();
if(n==r){
cout<<" CONGRULATIONS !! "<<endl<<"\b";
exit(0);
}
else if(n>r){
cout<<"Too High"<<endl;
cout<<"You have " << 5-(i+1)<< " tries "<<endl;
}
else{
cout<<"Too low"<<endl;
cout<<"You have " <<5- (i+1) << " tries"<<endl;
}
}
cout<<"The number was \t" << r <<endl;
return 0;
}
0 Comments