FUNCTIONS write psuedocode ONLY to design a complete slot machine program. The o
ID: 3687231 • Letter: F
Question
FUNCTIONS
write psuedocode ONLY to design a complete slot machine program.
The object of the game is to get 2 or 3 of the same numbers out of a total of 3 digits (each digit is in the range 1-9).
The specifications are listed below.
Welcome the user with an introduction and ask how much money they want to put in the slot machine.
Ask the user how much of their money they want to bet
Generate the three digits and show them to the user (hint: you will need to generate each digit separately.)
Any 3 matching digits = Win ten 10 times your bet
Any 2 matching digits = Win 2 times your bet
Anything else = Lose your bet
Tell the user how much they won or lost and how much money they have remaining
Allow the user to play again, but only if they have money left
When the user is out of money, thank them and end the game
Make sure that you are validating the things the user is doing. For example, don't let them make a bet higher than the amount they put in the machine.
Use at least two FUNCTIONS to modularize the program (these functions must be written by you and they must pass and/or return arguments).
BOLD your functions so that I can clearly see them in the code.
Show every step if possible
Explanation / Answer
#include <iostream>
#include <cstdlib>
#include <ctime>
int main(){
srand(time(0));
int betMoney=1000,choice,bet;
std::cout << "#### Slot Machine ! ## Have Fun ## ";
while(true){
std::cout << "what you want to do? (1)Play (2)Go home ";
std::cin >> choice;
switch(choice){
case 1:
std::cout << "so, lets start the game!!! ";
while(betMoney>0){
std::cout << "you have " << betMoney << " bucks to bet. " << "how much money you want to bet? ";
std::cin >> bet;
if(bet>betMoney){
std::cout << "you do not have this amount of money! Try another amount. ";
std::cin >> bet;
}else if(bet<=0){
std::cout << "your bet need to be more than 0 bucks budy! Try it again! ";
std::cin >> bet;
}else{
std::cout << "you are betting "<< bet << "bucks. so lets roll the gears! ";
int r1= 2 + rand() % ((7 + 1) - 2);
int r2= 2 + rand() % ((7 + 1) - 2);
int r3= 2 + rand() % ((7 + 1) - 2);
std::cout << "yours numbers are -> " << r1 << " | " << r2 << " | " << r3 << " | " << std::endl;
if(r1==r2==r3 and r1+r2+r3==21){
betMoney=betMoney + (bet*10); // all 7
std::cout << ">>>7<<< ";
std::cout << "you win! " << bet*10 << " bucks! ";
}else if(r1==r2==r3){
std::cout << ">>>5<<< ";
betMoney=betMoney + (bet*5); // all same
std::cout << "you win! " << bet*5 << " bucks! ";
}else if(r1==r2 or r1==r3 or r2==r3){
std::cout << ">>>3<<< ";
betMoney=betMoney + (bet*3); // 2 on tree
std::cout << "you win! " << bet*3 << " bucks! ";
}else{
//loose all
betMoney=betMoney - bet;
std::cout << "you lose your bet! ";
}
}
}
std::cout << "you have no money, go home! ";
break;
case 2:
std::cout << "bye bye ! ";
return 0;
break;
default:
if(std::cin.fail()){
std::cin.clear();
std::cin.ignore(10,' ');
}
std::cout << "you have just two options here man ";
break;
}
}
std::cin.get();
return 0;
}
sample output
#### Slot Machine ! ## Have Fun ##
what you want to do?
(1)Play (2)Go home
1
so, lets start the game!!!
you have 1000 bucks to bet.
how much money you want to bet?
500
you are betting 500bucks.
so lets roll the gears!
yours numbers are -> 2 | 4 | 2 |
>>>3<<<
you win! 1500 bucks!
you have 2500 bucks to bet.
how much money you want to bet?
100
you are betting 100bucks.
so lets roll the gears!
yours numbers are -> 3 | 6 | 7 |
you lose your bet!
you have 2400 bucks to bet.
how much money you want to bet?
2400
you are betting 2400bucks.
so lets roll the gears!
yours numbers are -> 6 | 6 | 4 |
>>>3<<<
you win! 7200 bucks!
you have 9600 bucks to bet.
how much money you want to bet?
you win! 7200 bucks!
you have 9600 bucks to bet.
how much money you want to bet?
9600
you are betting 9600bucks.
so lets roll the gears!
yours numbers are -> 2 | 6 | 6 |
>>>3<<<
you win! 28800 bucks!
you have 38400 bucks to bet.
how much money you want to bet?
0
your bet need to be more than 0 bucks budy!
Try it again!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.