Question

i need a program code on C++ for a slot machine that will be programmed on...

i need a program code on C++ for a slot machine that will be programmed on a MSP430G2553 micro controller. i will be using a push-button as the input or play button and 3 seven segment display as output or where the number will be shown rotating from 0 to 9.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>

using namespace std;

void slot_output(); // initializing functions
void combos(int x);
int CashMoney1 (int x);
void SpitMoney (int x, int y,int z);
int TrackMoney (int x, int y,int z,int money);

int main(){

slot_output(); // calling slot machine program

system("pause");
return 0;
}

void slot_output(){ // main slot machine program
int money = 100; //initial starting money
while (money =! 0){
string play;
cout << "Enter 00 to play!" << endl;
cin >> play;
if(play == "00"){
srand((unsigned)time(0));
int random_integer,i,j,k;
for(int index=0; index<3; index++){
random_integer = (rand()%5)+1; // calculating random number
combos(random_integer);
if (index == 0){
j = CashMoney1 (random_integer);
}
if (index == 1)
{
k = CashMoney1 (random_integer);
}
if (index == 2)
{
i = CashMoney1 (random_integer);
}
}
SpitMoney (j, k,i); // this tell the user how much they have won in a text
money = TrackMoney (j,k,i,money); // this is where i think the problem is because this should show how much money you have left
cout <<" You have "<< money << " left."<<endl;

}
}
cout << "You are out of money!"<<endl;
}
int TrackMoney (int x, int y,int z,int money){
int sum = x+y+z;
int cash;
if (x == 1 && y == 1){
cash = money + 5 ;
}
else if (x==1)
{
cash = money + 2;
}
else{

switch (sum){
case 30000 : cash = money + 250;break;
case 30: cash = money +20;break;
case 10030: cash = money +20;break;
case 10300: cash = money +14;break;
case 300: cash = money +14;break;
case 3000: cash = money +10;break;
case 13000: cash = money +10;break;
case 3:cash = money +7;break;
default: cash = money - 1; break;
}
}
return cash;
}

void SpitMoney (int x, int y,int z){
int sum = x+y+z;

if (x == 1 && y == 1){
cout << "You have won $5!"<< endl;
}
else if (x==1)
{
cout << "You have won $1!" << endl;
}
else{

switch (sum){
case 30000 : cout << " Congradualtions you have won $250!" << endl;break;
case 30: cout << " You have won $30!"<< endl;break;
case 10030: cout << " You have won $30!"<< endl;break;
case 10300: cout << " You have won $14!"<< endl;break;
case 300: cout << " You have won $14!"<< endl;break;
case 3000: cout << " You have won $10!"<< endl;break;
case 13000: cout << " You have won $10!"<< endl;break;
case 3:cout << " You have won $7!"<< endl;break;
default: cout << " You have lost $2!"<< endl;break;
}
}

}


int CashMoney1 (int x){ // i used this function so i can sort the possiable output combinations
int n;
n =0;

switch (x){
case 1: n++; break;
case 2: n = 10; break;
case 3: n = 100; break ;
case 4: n = 1000; break;
case 5: n = 10000; break;
}
return n;
}

void combos(int x){

switch (x){
case 1: cout<< " Cherry "; break;
case 2: cout<< " Bell "; break;
case 3: cout<< " Plum "; break ;
case 4: cout<< " Orange "; break;
case 5: cout<< " Bar "; break;
}
}

Add a comment
Know the answer?
Add Answer to:
i need a program code on C++ for a slot machine that will be programmed on...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need the VHDL code for this pls. Figure 1 Design a soda machine controller that...

    I need the VHDL code for this pls. Figure 1 Design a soda machine controller that can dispense two kinds of soda. If S1 Sel is selected, soda1 2. is dispensed, if S2Sel is selected then soda2 is dispensed. Each soda costs 75 cents and your machine accepts quarters only. The coin sensor has three outputs to detect first coin, second coin and the third coin. Once the soda is dispensed, the controller must be reset to be able to...

  • I need help with doing these tasks for code composer Lab 3 - Branching, Push Button...

    I need help with doing these tasks for code composer Lab 3 - Branching, Push Button and LEDs-Reading Assignment in this lab, we are going to control a LED via a push button- using general purpose digital 10 for both input (button) and output (LED) on port 1 - using Code Composer Studio. Furthermore, we are going to use a branch instruction to create an IF-ELSE structure in assembly to determine if the LED should be lit up based on...

  • need a C Code to show the 7 segment from 0-9 and A-F. thank you Software...

    need a C Code to show the 7 segment from 0-9 and A-F. thank you Software The segment LEDs are driven through different GPIO Ports that are defined as digital outputs. The predefined hexadecimal encoding values need to be shifted to the corresponding bit in order to light up the correct segment LED on different Ports. The program counts from 0 through 15 with 1 sec interval, then rolls over to 0 again. The count values are shown on the...

  • I need help writing a C programming code. I am trying to create a program that...

    I need help writing a C programming code. I am trying to create a program that returns ANY given number's decimal value as an Integer (Whole number). Examples: User input: 0.35 Output: 35 User input: 1.465 Output: 465 User input: 10.6054 Output: 6054

  • I need the following done in MASM (Assmebly or ASM) This program must use Irvine Library and the outline for the code is...

    I need the following done in MASM (Assmebly or ASM) This program must use Irvine Library and the outline for the code is below (Kip irvine) Write an assembly language program to input a string from the user. Your program should do these two things: 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in:   ...

  • I need help with this code: Write a program that calculates the future value of an...

    I need help with this code: Write a program that calculates the future value of an investment at a given interest rate for a specified number of years. The formula for the calculation is as follows: futureValue = investmentAmount * (1 + monthlyInterestRate)years*12 Use text fields for interest rate, investment amount, and years. Display the future amount in a text field when the user clicks the Calculate button, as shown in the following figure. It needs to be done in...

  • 4. Design a combinational circuit for a BCD to seven-segment code converter that will input a...

    4. Design a combinational circuit for a BCD to seven-segment code converter that will input a BCD number and output t on a seven segment common- anode display. The code converter will only display the number 8. Thoe converter wil turn the display OFF for all other valid BCD digits except digit 9 which will never occur. Draw a schematic. Show all steps clearly.

  • Design a program using Python and using from flask Import flask that generates a lottery number...

    Design a program using Python and using from flask Import flask that generates a lottery number but in a website.. The program should have an Integer array with 9 elements. Write a loop that steps through the array, randomly generating a number in the range of 0 through 42 for each element. (Use the random function) Then write another loop that displays the contents of the array. Each number should be displayed as a list, the numbers should be generated...

  • Objective: In this lab, we will learn how we can design sequential circuits using behavioral mode...

    Just need the code for the random counter,Thanks Objective: In this lab, we will learn how we can design sequential circuits using behavioral modelling, and implementing the design in FPGA. Problem: Design a random counter with the following counting sequence: Counting Sequence: 04 2 9 168573 Design Description: The counter has one clock (Clock), one reset (Reset), and one move left or right control signal (L/R) as input. The counter also has one 4bit output O and one 2bit output...

  • Hello I am confused about this C++ program. I need to create a payroll C++ program...

    Hello I am confused about this C++ program. I need to create a payroll C++ program following these steps. Source file structure Your program will consist of three source files: main.cpp the main program Payroll.hppclass declaration for the Payroll class. Make sure you have an include guard. Payroll.cpp Payroll's member functions Class definition Create a Payroll class definition. The class has private members which originate from user input: number of hours worked hourly rate float float - and private members...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT