Advertisement
Guest User

ex19

a guest
Feb 21st, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include<stdlib.h>
  2. #include<conio.h>
  3. #include<iostream>
  4. #include<time.h>
  5.  
  6. using namespace std;
  7.  
  8. int suma = 0 , user;
  9. bool win = false;
  10.  
  11. int generate_random() {
  12.     int n = 10;
  13.     srand(time(NULL));
  14.     int g = rand() % n;
  15.     return g;
  16.  
  17. }
  18.  
  19. int main() {
  20.     while (suma <= 100) {
  21.         int calculator = generate_random();
  22.         while (suma + calculator <= 89) {
  23.             suma = suma + calculator;
  24.             cout << calculator << "\n";
  25.             break;
  26.         }
  27.         if (suma >= 90) {
  28.             calculator = 100 - suma;
  29.             cout << calculator << "\n";
  30.             suma = suma + calculator;
  31.         }
  32.  
  33.         if (suma == 100) {
  34.             win = false;
  35.             cout << "Ai pierdut!";
  36.             break;
  37.         }
  38.  
  39.         cin >> user;
  40.         while (suma + user > 100) {
  41.             cin >> user;
  42.         }
  43.         suma = suma + user;
  44.         cout << "Suma: " << suma << "\n";
  45.         if (suma == 100) {
  46.             win = true;
  47.             cout << "Ai castigat!";
  48.             break;
  49.         }
  50.  
  51.     }
  52.     _getch();
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement