Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do I get rid of the errors with this c++ code? #include <iostream> #include

ID: 3626194 • Letter: H

Question

How do I get rid of the errors with this c++ code?

#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

int GetBet();
string PullOne();
int GetPayMultiplier(string s1, string s2, string s3);
void Display(string s1, string s2, string s3, int winnings);


int main()
{




}

int GetBet()
{
int theBet;
cout << "Please place a bet from $1 to $100. Do not include $ in your input. 0 to quit";
cin >> theBet;
while (theBet != 0) // I know this is wrong - i have to change it in a bit
{
if (theBet > 100 || theBet < 0)
{
cout << "Please input a valid number";
continue;
}
else if (theBet > 0 && theBet < 100)
return (theBet);
}
return 0;
}

string PullOne()
{
int slotChoices = 4;
string slotPull[slotChoices];
slotPull[0] = "cherries";
slotPull[1] = "BAR";
slotPull[2] = "space";
slotPull[3] = "7";
return slotPull[rand() % 3];
}

/*Select one option from the four below. All options are worth the same number of points. The more advanced options are provided for students who find the basic ones too easy and want more of a challenge. Make sure you have read and understand the Modules Information About Programming Assignments and Style Rules for Assignments before submitting this assignment. Hand in only one program, please.
For this assignment you will have to investigate the use of the C++ random generator function, rand(). Rand() produces a random integer in the range of 0 to RAND_MAX (a constant defined in the stdlib, automatically included in your projects). Among the places you can look for help are the following web sites:
• http://www.cplusplus.com/ref/cstdlib/rand.html
• http://www.daniweb.com/tutorials/tutorial1769.html
OPTION A (Basic): A Simple Slot Machine
The program will loop, asking the user for a bet amount from 0 to 100 (assume dollars, you can use ints or longs). If the user types a 0 that means he/she wants to quit. Otherwise, accept the amount as their bet and simulate a slot machine pull. Your program will print out a line that looks like a slot machine result containing three strings. Some examples are: BAR 7 BAR, 7 7 cherries, cherries BAR space, space BAR BAR, or cherries cherries BAR.
• Each of the three positions in the string could be one of the following: "BAR", "7", "cherries" or "space".
• Each of the three output positions is determined randomly with equal probability: there is 1/4 or 25% chance of any one of the four in any position (this is where you need the rand() function).
• The following combinations should pay the bet as shown (note ORDER MATTERS):
? cherries [not cherries] [any] pays 3 x bet (3 times the bet)
? cherries cherries [not cherries] pays 10 x bet
? cherries cherries cherries pays 20 x bet
? BAR BAR BAR pays 35 x the bet
? 7 7 7 pays 50 x the bet
• After the pull, display the three strings. If the user did not win, tell him/her "Sorry, you lose.". If he won, pay him by displaying his winnings (his original bet times the winning factor from the above table). Then, repeat the whole process by requesting another bet amount.
You will have to use methods as follows to get credit for this assignment:
• int GetBet() prompts the the user for input and returns the bet amount as a functional return.
• string PullOne() returns a random string from the four possibilities as a functional return (not a parameter change!) It is called by the client (your main()) three times to generate the three Strings.
• int GetPayMultiplier(string s1, string s2, string s3) computes the multiplier 3, 10, etc from the above table. It returns this value as a functional return. This would be called from your client (main()) after PullOne() has been called three times to generate three strings which would be passed to this method. Note that it does not compute cash winnings but only the pay multiplier.
• void Display(string s1, string s2, string s3, int winnings) will display the result of the pull and report the winnings. Winnings should be pre-computed by main() before calling this method using the value from GetBet() and the value from GetPayMultiplier(). Display() merely reports this number (after showing the pull strings). If there are no winnings, the client should pass a 0 as an argument to Display() and Display() should tell the user "Sorry", not something like "You won 0 dollars."
Communicate all values as parameters or return values, not through globals. The meaning of these terms and examples are contained in the module reading.
Also, I will emphasize that in keeping with the separation of I/O and computation, we would not have any method other than Display() output results to the screen, and Display() is called frommain(), not from any other method. Similarly, GetBet() is the only method that does input. The other methods, PullOne() and GetPayMultiplier() do no input, no output and do not call any methods that do input or output. Let's keep that idea fresh as we learn new tools like methods and classes.
Provide a minimum of 10 "pulls" in your run to demonstrate that the results are adequately random and you are paying out the correct amount.
Position counts! If you read the above bullet that contains the warning "ORDER MATTERS", you will see that cherries bar cherries pays 3x while cherries cherries bar pays 10x and bar cherries cherriespays nothing.



*
*/

Explanation / Answer

There are multiple issues with this code.

To begin with, in the PullOne() function definition, you are modding by 3. However, there are 4 possible choices, therefore, mod by 4.

The next issue is in your function prototypes. In the prototypes, you do not give names to the data you're passing in, just the types. For example, void Display should look like:

void Display (string, string, string, int);    //not void Display(string s1, string s2, string s3, int winnings);

Another issue is in your GetBet() function, you don't have to do the else if check. Just turn it into an else clause.

Another issue is in that if check, don't forget to check to see if the bet is <= 0, not just < 0.

I already have the solution to this problem coded in C++ if you run into issues.

Good Luck,

Cameron

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote