Code.GeekInterview.com
 
Code Samples C++
 

Random Number Game


Code ResourceAuthor: vimal.fire  

Difficulty Level:

Published: 31st Jan 2008   Read: 6980 times  

Filed in: C++
Add Comment


 

 

Sponsored Links


 

 

This makes use of the rand() function of math.h to create a random int between 0 and 50 you are given 5 chances to find the number.

 


Sample Code
  1. #include<iostream.h>
  2. #include<math.h>
  3. #include<conio.h>
  4. #include<stdlib.h>
  5.  
  6. void main()
  7. {int magic,get;
  8.  
  9. top:
  10. clrscr();
  11. cout<<"Simple game by VIMAL n";
  12. do{
  13. magic=rand();}while(magic>50);
  14. cout<<"you have 5 trails to figure out the magic number that lies b/w 0 and 50";
  15.  
  16. for(int i=0;i<5;i++)
  17. {
  18. cout<<endl<< "ntrial:" << i+1 <<"  Enter the number between 0 and 50:";
  19. cin>>get;
  20.  
  21. if(get==magic)
  22. {cout<< "n *****WINNER*****";goto last;}
  23.  
  24. (magic>get) ? cout<<"nYou're number is SMALLER" : cout<<"nYou're number is LARGER";
  25. }
  26. cout<<"nYOU LOSE...the number was "<<magic;
  27. last: cout<<" wanna try again (y/n)";
  28. char yn;
  29. cin>>yn;
  30. if(yn=='y')
  31. goto top;
  32.  
  33. }
  34. ?>
Copyright GeekInterview.com


Next Article: C++ Swap Numbers


 

Latest Code Samples

 

Popular Code Samples

 

Related Code Samples

 

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    



Popular Coders

# Coder NameHits
1. Priya36671
2. chowsys14958
3. bipin_vaylu13579
4. raghu.mohindru8719
5. Subashini7235
6. vimal.fire6981
7. rachittyagi6629
8. venki_madesh6209
9. prabha6193
10. vipin gupta5907

Active Coders

Refined Tags