Advertisement
Garey

rado_program

Oct 25th, 2017
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <time.h>
  4. #include <conio.h>
  5.  
  6. using namespace std;
  7.  
  8. void PlaceCursor(const int x, const int y);
  9. void clearScreen();
  10. void GameRules();
  11.  
  12. int main() {
  13.   int first_number, second_number, third_number, money, sum_money = 0;
  14.   char choice;
  15.  
  16.   GameRules();
  17.   if(getch())
  18.     goto repeat1;
  19.  
  20.   repeat1:
  21.   system("cls");
  22.   cout << "Enter your money: ";
  23.   cin >> sum_money;
  24.  
  25.   if(sum_money > 200 || sum_money < 0  || !cin) {
  26.     cout <<  "Error: Invalid input";
  27.     Sleep(200);
  28.     goto repeat1;
  29.   }
  30.  
  31.   repeat:
  32.   srand(time(NULL));
  33.   cout << "Enter bet: (max. 10 leva) ";
  34.   cin >> money;
  35.  
  36.   if(money > 10 || money < 0  || !cin) {
  37.     cout <<  "Error: Invalid input";
  38.     Sleep(200);
  39.     goto repeat;
  40.   }
  41.       system("cls");
  42.   while(!_kbhit() || sum_money <= 0) {
  43.     clearScreen();
  44.  
  45.     first_number = (rand() % (9 - 1));
  46.     second_number = (rand() % (9 - 1));
  47.     third_number = (rand() % (9 - 1));
  48.  
  49.     cout << first_number << second_number << third_number;
  50.     Sleep(50);
  51.   }
  52.  
  53.   if(first_number == second_number == second_number) {
  54.     sum_money += money;
  55.     cout << "\nYou won " << money << " leva. Now you have " << sum_money << " leva.";
  56.   } else {
  57.     sum_money -= money;
  58.     cout << "\nYou lost " << money << " leva. Now you have " << sum_money << " leva.";
  59.   }
  60.  
  61.   cout << "\n\nTry again? (y/n)";
  62.   cin >> choice;
  63.  
  64.   if(choice == 'y') {
  65.     goto repeat;
  66.   }
  67.  
  68.   return 0;
  69. }
  70.  
  71. void clearScreen()
  72. {
  73.     HANDLE hOut;
  74.     COORD Position;
  75.  
  76.     hOut = GetStdHandle(STD_OUTPUT_HANDLE);
  77.  
  78.     Position.X = 0;
  79.     Position.Y = 0;
  80.     SetConsoleCursorPosition(hOut, Position);
  81. }
  82.  
  83. void GameRules() {
  84.   PlaceCursor(45, 3);
  85.   cout << "Centered Text for rules" << endl;
  86.   PlaceCursor(37, 4);
  87.   cout << "Press any key to continue to the program";
  88. }
  89.  
  90. void PlaceCursor(const int x, const int y) {
  91.  
  92.     HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  93.  
  94.     COORD PlaceCursorHere;
  95.     PlaceCursorHere.X = x;
  96.     PlaceCursorHere.Y = y;
  97.  
  98.     SetConsoleCursorPosition(hConsole, PlaceCursorHere);
  99.     return;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement