Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
cppPyGuessTheNum2
//g++ 7.4.0 //cppPyGuessTheNum2: C++ equivalent of PyGuessTheNum2 program (created on May 03,2022) //this code is created by Rezaul Hoque on May 04,2022; //contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https://rezaulhoque.wordpress.com,https://hoquestake.blogspot.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> #include <cstdlib> #include <ctime> enum Status{Awesome, Bravo,GoodJob,NiceTry,HecticTry}; int main() { int num,guess,count,n=5; srand(time(0)); num=rand()%15+1; Status s[]={Awesome, Bravo,GoodJob,NiceTry,HecticTry}; for(count=1;count<=5;count++) { std::cout<<"Guess a number between 1 and 15:\n"; std::cin>>guess; if(num<guess) std::cout<<"Number is lower.\n"; else if(num>guess) std::cout<<"Number is higher.\n"; else break; } if(num==guess){ std::cout<<"Congratulations! "<<" You guessed it in "<<count<<" tries.\n"; if(s[count-1]==Awesome) std::cout<<"You are awesome!"; if(s[count-1]==Bravo) std::cout<<"Well done!"; if(s[count-1]==GoodJob) std::cout<<"Good!"; if(s[count-1]==NiceTry) std::cout<<"Nice Try!"; if(s[count-1]==HecticTry) std::cout<<"What an hectic effort!"; } else std::cout<<"Sorry! You failed."<<" The number is "<<num<<".\n"; return 0; }
run
|
edit
|
history
|
help
0
OneANOVA
doubly
error
Stock buy/sell
Iviewb
E. Bus Number
Policy based smart pointer
subset sum=k(Recursion)
test yield
Updated Linked Lists - 5/10/2017 V4.0