Advertisement
rado_dimitrov66

Number<> Game

Nov 7th, 2023 (edited)
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | Gaming | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. int genNumber(int currentNum) {
  8.  
  9.     int number;
  10.  
  11.     do
  12.     {
  13.         srand(time(NULL));
  14.         number = rand() % 50 + 1;
  15.  
  16.     } while (currentNum == number);
  17.  
  18.  
  19.     return number;
  20. }
  21.  
  22. int main()
  23. {
  24.     int newNum;
  25.     int level = 1;
  26.     int point = 0;
  27.     int currentNum = 0;
  28.     char choose;
  29.  
  30.     currentNum = genNumber(currentNum);
  31.  
  32.     cout << "The current number is: " << currentNum << endl;
  33.  
  34.  
  35.     while (level < 11) {
  36.  
  37.         cout << "" << endl;
  38.         cout << "Choose < or >[1 - < , 2 - >]: ";
  39.         cin >> choose;
  40.  
  41.         if (choose == '1' || choose == '2') {
  42.  
  43.             newNum = genNumber(currentNum);
  44.  
  45.  
  46.             if (currentNum > newNum && choose != '1' || currentNum < newNum && choose != '2') {
  47.  
  48.                 cout << "" << endl;
  49.                 cout << "Game Over !!! Good luck next time !!!" << endl;
  50.                 cout << "The last number is: " << newNum;
  51.                 cout << "" << endl;
  52.  
  53.                 cout << "Play again [y-Yes]: ";
  54.                 cin >> choose;
  55.  
  56.                
  57.                 if (choose == 'y' || choose == 'Y') {
  58.                     level = 1;
  59.                     point = 0;
  60.  
  61.                     currentNum = genNumber(newNum);
  62.  
  63.                     system("CLS");
  64.  
  65.                     cout << "Startin new game........" << endl;
  66.                     cout << "The current number is: " << currentNum << endl;
  67.                    
  68.                     continue;
  69.                 }
  70.                 else {
  71.                     exit(0);
  72.                 }
  73.  
  74.             }
  75.  
  76.  
  77.             currentNum = newNum;
  78.  
  79.             if (level < 10) {
  80.  
  81.                 cout << "" << endl;
  82.                 cout << "Time is new choose!!! Good luck !!!" << endl;
  83.                 cout << "The number is: " << currentNum << endl;
  84.             }
  85.  
  86.             point += level;
  87.             level++;
  88.         }
  89.         else {
  90.             continue;
  91.         }
  92.  
  93.  
  94.     }
  95.  
  96.  
  97.     if (level == 11) {
  98.  
  99.         system("CLS");
  100.  
  101.         cout << "" << endl;
  102.         cout << "The last number: " << currentNum << endl;
  103.         cout << "You win !!!" << endl;
  104.         cout << "Your points are: " << point << endl;
  105.         cout << "Your level is: " << level - 1 << endl;
  106.     }
  107.  
  108.     return 0;
  109. }
  110.  
  111.  
  112.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement