Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <time.h>
- #include <conio.h>
- using namespace std;
- void PlaceCursor(const int x, const int y);
- void clearScreen();
- void GameRules();
- int main() {
- int first_number, second_number, third_number, money, sum_money = 0;
- char choice;
- GameRules();
- if(getch())
- goto repeat1;
- repeat1:
- system("cls");
- cout << "Enter your money: ";
- cin >> sum_money;
- if(sum_money > 200 || sum_money < 0 || !cin) {
- cout << "Error: Invalid input";
- Sleep(200);
- goto repeat1;
- }
- repeat:
- srand(time(NULL));
- cout << "Enter bet: (max. 10 leva) ";
- cin >> money;
- if(money > 10 || money < 0 || !cin) {
- cout << "Error: Invalid input";
- Sleep(200);
- goto repeat;
- }
- system("cls");
- while(!_kbhit() || sum_money <= 0) {
- clearScreen();
- first_number = (rand() % (9 - 1));
- second_number = (rand() % (9 - 1));
- third_number = (rand() % (9 - 1));
- cout << first_number << second_number << third_number;
- Sleep(50);
- }
- if(first_number == second_number == second_number) {
- sum_money += money;
- cout << "\nYou won " << money << " leva. Now you have " << sum_money << " leva.";
- } else {
- sum_money -= money;
- cout << "\nYou lost " << money << " leva. Now you have " << sum_money << " leva.";
- }
- cout << "\n\nTry again? (y/n)";
- cin >> choice;
- if(choice == 'y') {
- goto repeat;
- }
- return 0;
- }
- void clearScreen()
- {
- HANDLE hOut;
- COORD Position;
- hOut = GetStdHandle(STD_OUTPUT_HANDLE);
- Position.X = 0;
- Position.Y = 0;
- SetConsoleCursorPosition(hOut, Position);
- }
- void GameRules() {
- PlaceCursor(45, 3);
- cout << "Centered Text for rules" << endl;
- PlaceCursor(37, 4);
- cout << "Press any key to continue to the program";
- }
- void PlaceCursor(const int x, const int y) {
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- COORD PlaceCursorHere;
- PlaceCursorHere.X = x;
- PlaceCursorHere.Y = y;
- SetConsoleCursorPosition(hConsole, PlaceCursorHere);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement