Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ctime>
- #include <cstdlib>
- #include <iostream>
- #include <limits>
- using namespace std;
- void game()
- {
- int GAME_account=0;
- int dice_one;
- int dice_two;
- int dice_three;
- int dice_four;
- int GAME_bet=0;
- int points_user=0;
- int points_computer=0;
- bool part1 = true;
- bool part2 = true;
- bool part3 = true;
- while (part1) {
- if (GAME_account>100) {
- part2=true;
- } else
- cout << "How much money do you want to put into your game account?"<<endl;
- cin >> GAME_account;
- if ((GAME_account>5000)|| (GAME_account<100) ) {
- cout << "You can bet max 5000 and min 100" << endl;
- part1 = true;
- part2=false;
- } else {
- cout << "your account is loaded with," <<GAME_account <<endl;
- part1=false;
- part2= true;
- }
- }
- while (part2) {
- cout<< " We are now starting the game. The first one to win two times winns. To start the game you need to bet 100,300 or 500, how much do you want to bet?"<< endl;
- cin>> GAME_bet;
- if ((GAME_bet == 500) || (GAME_bet == 300) || (GAME_bet == 100)) {
- part2=false;
- cout << "You choose to bet " << GAME_bet << endl;
- GAME_account = GAME_account - GAME_bet;
- cout << "You now have on your account " << GAME_account << endl;
- part3=true;
- } else{
- cout << "please pick to bet between 100, 300, 500" << endl;
- part2 = true;
- part1=false;
- part3=false;
- }
- }
- while (part3) {
- cout<< "game begins"<<endl;
- cout<< "press ENTER to throw your first dice" <<endl;
- cin.get();
- dice_one = rand() % 6 + 1;
- cout << dice_one << endl;
- cout << "press ENTER to throw your second dice" << endl;
- cin.get();
- dice_two = rand() % 6 + 1;
- cout << dice_two << endl;
- cout << "Your numbers are now:" << endl;
- cout<< dice_one<< " and "<< dice_two<< endl;
- cout << "press ENTER to let the computer throw its first dice" << endl;
- cin.get();
- dice_three = rand() % 6 + 1;
- cout << dice_three << endl;
- cout << "press ENTER to let the computer throw its second dice" << endl;
- cin.get();
- dice_four = rand() % 6 + 1;
- cout << dice_four << endl;
- cout << "The computers numbers are now:" <<endl;
- cout<< dice_three<< " and "<< dice_four<< endl;
- if (std::max(dice_three,dice_four)==std::max(dice_two,dice_one)) {
- cout << "Oh, tie, lets start the round again" << endl;
- } else if (std::max(dice_three,dice_four) < std::max(dice_two,dice_one)) {
- cout << "You won this round" << endl;
- points_user++;
- } else {
- cout << "You lost this round" << endl;
- points_computer++;
- }
- cout << "Points are now: \nUser-Computer" << endl;
- cout << points_user;
- cout << "-";
- cout << points_computer << endl;
- if (points_computer==2){
- part3=false;
- cout << "im sorry, you lost better luck next time" << endl;
- cout << "You now have left on your account " << endl;
- cout << GAME_account << std::endl;
- } else if (points_user == 2)
- part3=false;
- cout << "you won the game with total" << endl;
- cout << GAME_bet * 2 << endl;
- cout << "You now have left :" << endl;
- GAME_account = GAME_account + (GAME_bet * 2);
- cout<< GAME_account << std::endl;
- }
- }
- int main()
- {
- char answer;
- srand (time(0));
- std::cout << "Welcome to the dice game!" << std::endl <<
- "Press p to play and e to exit" << std::endl;
- do {
- std::cin >> answer;
- std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- answer = std::tolower(answer);
- } while ((answer != 'p') && (answer != 'e'));
- if (answer == 'p') {
- do {
- game();
- std::cout << "do you want to play again?" << std::endl;
- std::cin >> answer;
- } while (std::tolower(answer) == 'y');
- }
- std::cout << "game over" << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment