Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

URGENT- PLEASE HELP! I seem to have a logic error in my code that is causing my code to not perform math right Like for

URGENT- PLEASE HELP! I seem to have a logic error in my code that is causing my code to not perform math "right" Like for instance if I have $1000 dollars, then I place a bet of $50 and win $100 then that is a net gain of $50 and so the total amount of money you should have after that is $1050 NOT $1100 like is being displayed. So please please please help me troubleshoot this logic error, thanks so much. I'lll attach my assignment if you need some reference for whats going on:

Logic Error:

image text in transcribed

My Code:

#include

#include

#include

#include

#include

#include

using namespace std;

void generate_summary(vector wager,vector winning)

//generates summary

{

int i;

int largest_wager = INT_MIN, smallest_wager = INT_MAX;

int largest_winning = INT_MIN, smallest_winning= INT_MAX;

cout

for (i=0 ; i

{

cout

largest_wager = max( largest_wager ,wager[i]) ;

smallest_wager = min( smallest_wager,wager[i]) ;

largest_winning = max( largest_winning,winning[i]) ;

if(winning[i]>0) // find smallest win having positive value

smallest_winning = min( smallest_winning,winning[i]) ;

}

if(smallest_winning==INT_MAX) smallest_winning=0 ; // no wins

cout

cout

cout

cout

cout

}

int main()

{

unsigned int seed ; //seed

int bet , money =1000 ,i ;

int reel[3] ;

vector wager , winning ; // vectors for wager and win

printf("Input a seed: ") ;

cin >> seed ; //seed value

while(cin.fail()) // input until seed is valid

{

cin.clear();

cin.ignore(256,' ');

printf("Input a seed: ") ;

cin >> seed ;

}

cout

cout

cin >> bet ;

if(bet==0)

{

cout

return 0 ;

}

srand(seed);// seed the random results

while(1) // game starts

{

if(bet==0)

{

generate_summary(wager,winning) ; // function call

break ;

}

while(bet > money)

{

cout

cout

cin >> bet ;

if(bet==0)

{

generate_summary(wager,winning) ; // function call

break ;

}

}

wager.push_back(bet) ; // push bet to wager vector

for(i=0; i

{

int random_no = 2 + ( rand() % 8 ) ; //random int between [2,7]

reel[i] = random_no ;

}

cout

if(reel[0] == reel [1] == reel[2]) // if all reel values are equal

{

if(reel[0]==7) // jackpot !

{

cout

winning.push_back(10*bet) ;

money = money + 10 * bet ;

}

else // reel values equal but other than 7

{

cout

winning.push_back(2*bet) ;

money = money + 2 * bet ;

}

}

// if exactly two reel value matches

else if(reel[0] == reel[1] || reel[0] == reel[2] || reel[1] == reel[2])

{

cout

winning.push_back(2*bet) ;

money = money + 2 * bet ;

}

else // all reel values are distinct

{

cout

winning.push_back(0) ;

money = money - bet ;

}

cout

cout

cin >> bet ; //place next bet

}

return 0;

}

}

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Input a seed: 102 Your Money: $1000 Place a bet: 50 4 8 4 You won $100 Searc Your Money: $1100 Assignment You will be writing a program to simulate a slot machine. The player will start with $1000 and you will repeatedly ask the user how much money they wish to insert into the machine before spinning, or allow the player to quit. If the player runs out of money, the game is over. Additionally, the player cannot spend more money than they have available. You should store the player's wagers and winnings in order to output statistics when the user is done playing. Spinning and Payouts After placing a bet, the money is immediately subtracted from the player's balance. The slot machine has 3 reels which are spun after the lever is pulled. Each reel will randomly contain a integer value between 2 and 7 inclusive after being spun. If the all 3 reels have the value 7, the player obtained a jackpot and will receive the amount which they wagered times 10. If all 3 reels match, but contain a value other than 7, award the player their wagered amount times 5. Otherwise, if only 2 reels match, award the player their wager times 2. If none of the reels match, the player does not receive any earnings. Restrictions Hints 1. At the start, ask the user for a seed to use for the random number generator. Use this value to seed your random numbers. 2. Before each spin, show the user their current balance and ask for a wager. 3. The slot machine only accepts wagers containing whole dollar amounts. You may not enter any spare change. 4. You must use an array to store the value of each reel. 5. You must use a for loop to input the random values of each reel. 6. You must use a vector to store the amount of each wager. 7. You must use a vector to store the winnings of each spin. 8. If the user wagers an amount of O or less, stop playing and output play statistics. Additionally, if the user has a balance of $0 and is unable to wager, end the game and output play statistics. If the user never played and walks away immediately, do not output any statistics. 9. At the end, output a summary of each spin including the wager and amount won. Then output the smallest and largest wager, and the smallest non-zero winnings and the largest winnings from a single spin. Note that if the user never wins, the smallest and largest winnings displayed should be 0. Examples Text in red is user input. Input a seed: 102 Your money: $1000 Place a bet: $50 4 46 You won $100! Your money: $1050 Place a bet: $50 6 7 3 You didn't win Your money: $1000 Place a bet: $100 You won $200! Your money: $1100 Place a bet: $200 6 75 You didn't win Your money: $900 Place a bet: $0 You wagered $50 and won $100 u wagered $50 and won $0 You wagered $100 and won $200 You wagered $200 and won $0 Your smallest wager was $50 Your largest wager was $200 Your smallest winnings was $100 Your largest winnings was $200 Input a seed: YBMAZ Input a seed: 3 Your money: $1000 Place a bet: $ZAMBY Place a bet: $1 2 3 2 You won $2! Your money: $1001 Place a bet: $2 2 5 6 You didn't win. Your money: $999 Place a bet: $3 2 6 3 You didn't win. Your money: $996 Place a bet: $4 You won $20! Your money: $1012 Place a bet: $0 You wagered $1 and won $2 You wagered $2 and won $0 You wagered $3 and won $0 You wagered $4 and won $20 Your smallest wager was $1. Your largest wager was $4 Your smallest winnings was $2 Your largest winnings was $20 Input a seed: 130 Your money: $1000 Place a bet: $1000 5 3 2 You didn't win You are out of money! You wagered $1000 and won $0. Your smallest wager was $1000 Your largest wager was $1000 Your smallest winnings was $0 Your largest winnings was $0 Input a seed: 140 Your money: $1000 Place a bet: $0 You walked away without playing

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

More Books

Students also viewed these Databases questions

Question

What is different about C#s Sleep method, relative to Javas sleep?

Answered: 1 week ago