Well this class has blown my confidence all to 773H.
I need to know why this problem won't select and print 3 elements out of 6 when randomly selected. It only prints one word.
I need to know why it won''t display a running and updated total after each bet.
The problem is to design a slot machine that displays 3 (one-armed bandit type of words), The player starts with $100 dollars, enters the amount of his bet.
Three random words are display (out of a set of 6). no matches = balance - $10; 2 matches is bal= bal + (2* bet); 3 matches pays bal= bal +(bet *2). A fluctuating total is displayed after each bet.
Does one ever get to the point where it doesn't take 16 hours of work to have not found a solution?
int main()
{
int drums[3];
string Cherries, Oranges, Bells, Bars, Plums, Melons;
int g = rand()% 6;
int bal = 100;
int bet = 0;
int i = 0;
cout<<"Slot Machine"<<endl;
cout<<endl<<endl;
cout<<"Rules \n";
cout<<"You have $100.00 to start. \n";
cout<<"If none of the words match you lose $10.00.\n";
cout<<"If 2 of the words match you win twice the amount of your bet.\n";
cout<<"If all 3 of the words match you win three times the amount of your bet."<<endl;
cout<<endl<<endl;
cout<<"Enter the amount you wish to bet. (control + c to quit)"<<endl;
cin>>bet;
}
//no matches
if(drums[0] != drums[1] && drums[1] != drums[2] && drums[0] != drums[2])
{
cout<<"You lost! No words matched. You have $ "<<endl;
bal = bal - 10;
//cout<<"Bet again? (control + c to quit)"<<endl;
}
//3 matches
if(drums[0] == drums[1] && drums[1] == drums[2])
{
cout<<"You won! 3 words matched. You have $ "<<endl;
bal = bal + (bet * 3);
cout<<"Bet again? (control + c to quit)"<<endl;
}
else
{
cout<<"You won! 2 words match. You have $ "<<endl;
bal = bal + (bet *2);
cout<<"Bet again? (control + c to quit)"<<endl;
}
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <stdbool.h>
usingnamespace std;
//function prototypes
//bool randomWords(string);
//global constants
int main()
{
int drums[3];
string Cherries, Oranges, Bells, Bars, Plums, Melons;
int g = rand()% 6;
int bal = 100;
int bet = 0;
int i = 0;
cout<<"Slot Machine"<<endl;
cout<<endl<<endl;
cout<<"Rules \n";
cout<<"You have $100.00 to start. \n";
cout<<"If none of the words match you lose $10.00.\n";
cout<<"If 2 of the words match you win twice the amount of your bet.\n";
cout<<"If all 3 of the words match you win three times the amount of your bet."<<endl;
cout<<endl<<endl;
cout<<"Enter the amount you wish to bet. (control + c to quit)"<<endl;
cin>>bet;
for(i=0; i<3; i++)
{
(g = (rand() % 6)+1);
}
switch(g)
{
case(0):
cout<<"Cherries"<<endl;
break;
case(1):
cout<<"Oranges"<<endl;
break;
case(2):
cout<<"Plums"<<endl;
break;
case(3):
cout<<"Bells"<<endl;
break;
case(4):
cout<<"Melons"<<endl;
break;
case(5):
cout<<"Bars"<<endl;
break;
default:
cout<<"Error: Invalid symbol."<<endl;
}
//no matches
if(drums[0] != drums[1] && drums[1] != drums[2] && drums[0] != drums[2])
{
cout<<"You lost! No words matched. You have $ "<<endl;
bal = bal - 10;
//cout<<"Bet again? (control + c to quit)"<<endl;
}
//3 matches
if(drums[0] == drums[1] && drums[1] == drums[2])
{
cout<<"You won! 3 words matched. You have $ "<<endl;
bal = bal + (bet * 3);
cout<<"Bet again? (control + c to quit)"<<endl;
}
else
{
cout<<"You won! 2 words match. You have $ "<<endl;
bal = bal + (bet *2);
}
return 0;
//end main
}
Firstly, line 18 is useless (and shouldn't even compile, you haven't included <string>).
Every time, you are overwriting "g" in your "for" loop at line 40. Also, you are never setting the values for "drums". You will need to put your switch statement within your for loop, and then have the case for "Cherries" set drums[i] to "Cherries", etc.