0 / 0 / 0
Регистрация: 26.07.2022
Сообщений: 4
|
|
1 | |
Задача. Игра "Casino". Нужно добавить еще одного игрока, для "состязание" Чем больше способов тем лучше31.10.2022, 12:30. Показов 281. Ответов 0
Метки нет (Все метки)
#include <iostream>
#include <string> // Needed to use strings #include <cstdlib> // Needed to use random numbers #include <ctime> using namespace std; void rules(); int main() { string playerName; int balance; // stores player's balance int bettingAmount; int guess; int dice; // stores the random number char choice; srand(time(0)); // "Seed" the random generator cout << "\n\t\t========WELCOME TO CASINO WORLD=======\n\n"; cout << "\n\nWhat's your Name : "; getline(cin, playerName); cout << "\n\nEnter the starting balance to play game : $"; cin >> balance; do { system("cls"); rules(); cout << "\n\nYour current balance is $ " << balance << "\n"; // Get player's betting balance do { cout << "Hey, " << playerName<<", enter amount to bet : $"; cin >> bettingAmount; if(bettingAmount > balance) cout << "Betting balance can't be more than current balance!\n" <<"\nRe-enter balance\n "; }while(bettingAmount > balance); // Get player's numbers do { cout << "Guess any betting number between 1 & 10 :"; cin >> guess; if(guess <= 0 || guess > 10) cout << "\nNumber should be between 1 to 10\n" <<"Re-enter number:\n "; }while(guess <= 0 || guess > 10); dice = rand()%10 + 1; if(dice == guess) { cout << "\n\nYou are in luck!! You have won Rs." << bettingAmount * 10; balance = balance + bettingAmount * 10; } else { cout << "Oops, better luck next time !! You lost $ "<< bettingAmount <<"\n"; balance = balance - bettingAmount; } cout << "\nThe winning number was : " << dice <<"\n"; cout << "\n"<<playerName<<", You have balance of $ " << balance << "\n"; if(balance == 0) { cout << "You have no money to play "; break; } cout << "\n\n-->Do you want to play again (y/n)? "; cin >> choice; }while(choice =='Y'|| choice=='y'); cout << "\n\n\n"; cout << "\n\nThanks for playing the game. Your balance is $ " << balance << "\n\n"; return 0; } void rules() { system("cls"); cout << "\t\t======CASINO NUMBER GUESSING RULES!======\n"; cout << "\t1. Choose a number between 1 to 10\n"; cout << "\t2. Winner gets 10 times of the money bet\n"; cout << "\t3. Wrong bet, and you lose the amount you bet\n\n"; } Добавлено через 16 минут Это я так попытался но не получилось. #include <iostream> #include <string> // Needed to use strings #include <cstdlib> // Needed to use random numbers #include <ctime> using namespace std; int main() { string playerName; string playerName2; int balance; // stores player's balance int balance2; int bettingAmount; int bettingAmount2; int guess; int guess2; int dice; // stores the random number char choice; srand(time(0)); // "Seed" the random generator cout << "\n\t\t========WELCOME TO CASINO WORLD=======\n\n"; cout << "\n\nType 1st players name : "; getline(cin, playerName); cout << "\n\nEnter the starting balance to play game for 1st player : $"; cin >> balance; cout << "\n\nType 2nd players name : "; getline(cin, playerName2); cout << "\n\nEnter the starting balance to play game for 2nd player : $"; cin >> balance2; do { system("cls"); cout << "\n\n" << playerName << "'s current balance - $ " << balance << "\n"; cout << "\n\n" << playerName2 << "'s current balance - $ " << balance2 << "\n"; // Get player's betting balance do { cout << "Hey, " << playerName << ", enter amount to bet : $"; cin >> bettingAmount; if (bettingAmount > balance) cout << "Betting balance can't be more than current balance!\n" << "\nRe-enter balance\n "; } while (bettingAmount > balance); do { cout << "And now, you " << playerName2 << ", enter amount to bet : $"; cin >> bettingAmount2; if (bettingAmount2 > balance2) cout << "Betting balance can't be more than current balance!\n" << "\nRe-enter balance\n "; } while (bettingAmount2 > balance2); // Get player's numbers do { cout << "" << playerName << " Guess any betting number between 1 & 10 :"; cin >> guess; if (guess <= 0 || guess > 10) cout << "\nNumber should be between 1 to 10\n" << "Re-enter number:\n "; } while (guess <= 0 || guess > 10); do // For 2nd player guessing number { cout << "" << playerName2 << " Guess any betting number between 1 & 10 :"; cin >> guess2; if (guess2 <= 0 || guess2 > 10) cout << "\nNumber should be between 1 to 10\n" << "Re-enter number:\n "; } while (guess2 <= 0 || guess2 > 10); dice = rand() % 10 + 1; // The dice logic starts for 1st if (dice == guess) { cout << "\n\nYou are in luck!! You have won Rs. << bettingAmount * 10"; balance = balance + bettingAmount * 10; } else { cout << "Oops, better luck next time !! You lost $ " << bettingAmount << "\n"; balance = balance - bettingAmount; } cout << "\nThe winning number was : " << dice << "\n"; cout << "\n" << playerName << ", You have balance of $ " << balance << "\n"; if (balance == 0) { cout << "You have no money to play "; break; } if (dice == guess2) // The logic for 2nd { cout << "\n\nYou are in luck!! You have won Rs. << bettingAmount * 10"; balance2 = balance2 + bettingAmount2 * 10; } else { cout << "Oops, better luck next time !! You lost $ " << bettingAmount2 << "\n"; balance2 = balance2 - bettingAmount2; } cout << "\nThe winning number was : " << dice << "\n"; cout << "\n" << playerName2 << ", You have balance of $ " << balance2 << "\n"; if (balance2 == 0) { cout << "You have no money to play "; break; cout << "\n\n-->Do you want to play again (y/n)? "; cin >> choice; } while (choice == 'Y' || choice == 'y'); cout << "\n\n\n"; cout << "\n\nThanks for playing the game. Your balance is $ " << balance << "\n\n"; return 0; }
0
|
31.10.2022, 12:30 | |
Ответы с готовыми решениями:
0
Чем больше тем лучше ЧБТЛ спасибо Чем больше ничего не делаешь - тем лучше =) Прошу оценить ПК. Чем больше мнений, тем лучше Файлы: найти команду, в которой гонорар одного игрока больше, чем у остальных Игра Ним с двумя кучами для одного игрока |
31.10.2022, 12:30 | |
31.10.2022, 12:30 | |
Помогаю со студенческими работами здесь
1
"Лишние" знания или чем больше, тем лучше? Игра Ним с тремя кучами для одного игрока без ограничений на количество забираемых камней пожалуйста решите. для вас эт ерунда(чем быстре тем лучше) Игра "Ним" с двумя кучами для одного игрока Чем больше даёшь места под Windows, тем больше она жрёт Искать еще темы с ответами Или воспользуйтесь поиском по форуму: |