Please revise and post solution on this page. I do not want to email anyone, nor
ID: 3661175 • Letter: P
Question
Please revise and post solution on this page. I do not want to email anyone, nor do I want a tutor. I have emailed 2 people before and none replied so I will not go down that route again. Please help me. This is due today (Friday)
if the code is too long for your liking, then I will accept a shorter as long as it works.
Modifications to be made:
Therefore, your main function should call showMenu() function first, then call takeChoice(), then depending on user choice, play Pick1 game or play Pick3 game, then call reportTotal() before showing the menu again or end the program.
>>> clarification: functions takeChoice1() and takeChoice2() will have to be combined into one function called takeChoice which allows user to pick either the game "pick 1" or the game "pick 3" <<<
Please make sure the revised code works 100%. I will rate...PROMISE!!
here is the code I was working with:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
double reportTotalWin(); //this function will take winnings from pick1 and pick3, calculate and return grand total winning.
void showMenu(); //this function will display ALL menu choices
int takeChoice1(); //this function will take, validate and return user choice selected from the menu choices from showMenu for pick 1
int takeChoice3(); //this function will take, validate and return user choice selected from the menu choices from showMenu for pick 3
//-------------------------------------------------------------------------------
int main ()
{
showMenu();
reportTotalWin();
int play;
cout << " Would you like to continue playing? Press 1 to continue or 2 to quit: ";
cin >> play;
if ( (play != 1)&&(play!=2) )
{
cout << " I'm sorry please enter a valid response ";
cout << " Enter 1 to continue or 2 to quit: ";
cin >> play;
}
else
if (play == 1)
{
takeChoice1();
takeChoice3();
reportTotalWin();
}
if (play == 2)
{
cout << " Oh, well this is ackward. See you next time!";
}
return 0;
}
//-------------------------------------------------------------------------------
double reportTotalWin()
{
double total, //the total of all winnings
total1, //the total won in pick 1 game
total2; //the total won in pick 3 game
static int winnings = 0; //everyone starts at $0 won in pick 1
static int winnings3 = 0; //everyone starts at $0 won in pick 3
//total1 = winnings += takeChoice1(); //not sure if these are correct
//total2= winnings3 += takeChoice3(); //not sure if these are correct
//total = total1 + total2; //not sure if these are correct
winnings += takeChoice1(); //winnings for pick 1 is 0 (or current # in winnings) + returned value from takeChoice1()
total1 = winnings; //assigns winnings to a total
winnings3 += takeChoice3(); //winnings for pick 3 is 0 (or current # in winnings3) + returned value from takeChoice3()
total2 = winnings3; //assigns winnings3 to another total
total = total1 + total2; //adds both totals to get grand total winnings of both games
cout << "---------------------------------------------------------------------- ";
cout << "Time for your winnings! ";
cout << "Pick 1: ";
cout << " Your winnings for Pick 1 is: $ " << winnings << endl;
cout << " Pick 3: ";
cout << " Your winnings for Pick 3 is: $ " << winnings3 << endl;
cout << "---------------------------------------------------------------------- ";
cout << "Your total winnings for everytime you played Pick 1 is: $" << total1 << endl;
cout << "Your total winnings for everytime you played Pick 2 is: $" << total2 << endl;
cout << "Your total winnings for all games is: $" << total << endl;
if (total <= 100)
{
cout << " You can continue playing if you please! ";
}
else {
cout << " You have reached the max amount you can win for today. Please play again another day. ";
system("END"); //causes program to end ...?
}
return total;
}
//-------------------------------------------------------------------------------
void showMenu(void)
{
cout << "Welcome to your daily Lucky Pick! ";
cout << "Where you can walk out with $100 daily! ";
cout << "When prompted you can decide if you want to play again. ";
cout << "--------------------------------------- ";
cout << " OFFICIAL RULES ";
cout << "--------------------------------------- ";
cout << " Pick 1: ";
cout << " Guess any number from 0 though 25, then press ENTER ";
cout << " A correct guess results in a winning of $2 ";
cout << "Pick 3: ";
cout << " Pick 1 special number from 1 through 25, but not 7 or 13 ";
cout << " Pick any 2 regular numbers from 1 through 10 ";
cout << " A correct special number guess results in a winning of $5 ";
cout << " Two correct regular number guesses result in a winning of $10 ";
cout << " A correct special number guess AND one regular number guess results in a winning of $50 ";
cout << " A correct guess of all 3 numbers results in a winning of $100 ";
return;
}
//-------------------------------------------------------------------------------
int takeChoice1()
{
int Rpick1=1+rand()%; //assigns random number for pick 1 with range 0-25
int pick1; //assigns user's pick 1
cout << " ---------------------------------------------------------------------- ";
cout << "Enter your number for pick 1: ";
cin >> pick1;
if(Rpick1 == pick1)
{
cout<<"----------------------------- ";
cout<<" YOU WON $2! ";
cout<<"----------------------------- ";
static int winnings = 2;
return winnings;
}
else
{
cout << "Sorry, your guess was not correct." << endl;
cout << "The number was "<< Rpick1 << endl;
return 0;
}
}
//-------------------------------------------------------------------------------
int takeChoice3()
{
int Rpick3n1= 1 + rand(); //assigns random number for pick 3 first number, range 1 through 10
int Rpick3n2= 1 + rand(); //assigns random number for pick 3 second number, range 1 through 10
int Rpick3Special; //sets up the random special number
srand(time(NULL)); //seeds the random number
do
{
Rpick3Special = 1+ rand()%; //assigns random number for pick 3 special number, range 1 though 25
}
while(Rpick3Special == 7 && Rpick3Special == 13); //finds random number again if it is 7 or 13
int pick3n1; //assigns user's pick 3 regular number 1
int pick3n2; //assigns user's pick 3 regular number 2
int pick3Special; //assigns user's pick 3 special number
cout << " Time for pick 3! ";
cout << "Pick your first regular number: ";
cin >> pick3n1 ;
cout << "Pick the second regular number: ";
cin >> pick3n2 ;
cout << "Now pick the special number: ";
cin >> pick3Special;
cout << endl;
cout << "Here are the numbers: "<<endl;
cout << "The 1st number was "<< Rpick3n1 << endl;
cout << "The 2nd number was "<< Rpick3n2 << endl;
cout << "The special number was "<< Rpick3Special << endl;
if((Rpick3n1 == pick3n1)&&(Rpick3n2 == pick3n2)&&( Rpick3Special == pick3Special))
{
cout << "---------------------------- ";
cout << " YOU WON $100!";
cout << "---------------------------- ";
return 100;
}
else if((Rpick3n1 == pick3n1)&&( Rpick3Special == pick3Special))
{
cout << "---------------------------- ";
cout << " YOU WON $50! ";
cout << "---------------------------- ";
return 50;
}
else if((Rpick3n2 == pick3n2)&&( Rpick3Special == pick3Special))
{
cout << "---------------------------- ";
cout << " YOU WON $50! ";
cout << "---------------------------- ";
return 50;
}
else if((Rpick3n1 == pick3n1)&&(Rpick3n2 == pick3n2))
{
cout << "----------------------------- ";
cout << " YOU WON $10! ";
cout << "----------------------------- ";
return 10;
}
else if((Rpick3n1 == pick3n1)||(Rpick3n2 ==pick3n2))
{
cout << "------------------------------------------- ";
cout << " Congrats, you matched a regular number! ";
cout << " But it does not qualify as a win. ";
cout << "------------------------------------------- ";
return 0;
}
else if( Rpick3Special == pick3Special )
{
cout << "------------------------------ ";
cout << " YOU WON $5! ";
cout << "------------------------------ ";
return 5;
}
else
{
cout << " Sorry no matching numbers. ";
return 0;
}
}
Explanation / Answer
firstly about your email route i want to say that not everyone is same....today itself i have helped a guy through his test and had solved his each and every question :)
anyways its a different topic, now towards your question, i have read your code its far from being correct, so some of the modification should be done....i will highlight the section of code so that you can compare it with your own code :)
here is your code with certain modifications :)
note: where ever it is mention your code and proposed code, you have to omit your code and include proposed code, your code is just shown for clarification, and the line in red is modified lines..
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
void reportTotalWin(); //this function will take winnings from pick1 and pick3, calculate and return grand total winning.
void showMenu(); //this function will display ALL menu choices
int pick1(); //this function will take, validate and return user choice selected from the menu choices from showMenu for pick 1
int pick3(); //this function will take, validate and return user choice selected from the menu choices from showMenu for pick 3
double total1 = 0; // global variable
double total2 = 0; // global variable
//-------------------------------------------------------------------------------
int main ()
{
showMenu();
static int winnings = 0; //everyone starts at $0 won in pick 1
static int winnings3 = 0; //everyone starts at $0 won in pick 3
int a = 0, b = 0; //to hold winning amount every time
int play;
// this while is included so that user can play as many times he wants unless he reaches the score of 100 or he presses 2
while (1)
{
//your code:
cout << " Would you like to continue playing? Press 1 to continue or 2 to quit: ";
//proposed code:
cout << " Would you like to play? Press 1 to continue or 2 to quit: ";
cin >> play;
//your code:
if ( (play != 1)&&(play!=2) )
{
cout << " I'm sorry please enter a valid response ";
cout << " Enter 1 to continue or 2 to quit: ";
cin >> play;
}
//proposed code:
//as your code only checks whether play is 1 or 2 for a single time and if user again enters a wrong number then your code do nothing, so here is the solution:
while(1)
{
if ( (play != 1)&&(play!=2) )
{
cout << " I'm sorry please enter a valid response ";
cout << " Enter 1 to continue or 2 to quit: ";
cin >> play;
}
else
break;
}
// new code to be added:
{
if (play == 1)
{
int x;
x = takeChoice();
while (1)
{
if ( (x != 1)&&(x!=2) )
{
cout << " I'm sorry please enter a valid response ";
x = takeChoice();
}
else
break;
}
if (x==1)
{
a = pick1();
winnings = winnings + a;
}
if (x==2)
{
b = pick3();
winnings3 = winnings3 + b;
}
reportTotalWin(winnings, winnings3);
}
if (play == 2)
{
cout << " Oh, well this is ackward. See you next time!";
exit (0); //this will cause program to end ..
}
}
return 0;
}
//-------------------------------------------------------------------------------
//corrected code:
void reportTotalWin(int winnings, int winnings3)
{
double total; //the total of all winnings
// total1 is already defined to take the total won in pick 1 game
// total2 is already defined to take the total won in pick 3 game
total1 = total1 + winnings; //now it is correct
total2 = total2 + winnings3; //now it is correct
total = total1 + total2; //now it is correct
cout << "---------------------------------------------------------------------- ";
cout << "Time for your winnings! ";
cout << "Pick 1: ";
cout << " Your winnings for Pick 1 is: $ " << winnings << endl;
cout << " Pick 3: ";
cout << " Your winnings for Pick 3 is: $ " << winnings3 << endl;
cout << "---------------------------------------------------------------------- ";
cout << "Your total winnings for everytime you played Pick 1 is: $" << total1 << endl;
cout << "Your total winnings for everytime you played Pick 2 is: $" << total2 << endl;
cout << "Your total winnings for all games is: $" << total << endl;
if (total <= 100)
{
cout << " You can continue playing if you please! ";
}
else {
cout << " You have reached the max amount you can win for today. Please play again another day. ";
exit (0); //this will cause program to end ..
}
}
//-------------------------------------------------------------------------------
// new code to be added:
int takeChoice()
{
int ch;
cout<<" Which game do you want to play: Enter 1 for Pick1 and 2 for Pick3";
cin>>ch;
return ch;
}
void showMenu(void)
{
cout << "Welcome to your daily Lucky Pick! ";
cout << "Where you can walk out with $100 daily! ";
cout << "When prompted you can decide if you want to play again. ";
cout << "--------------------------------------- ";
cout << " OFFICIAL RULES ";
cout << "--------------------------------------- ";
cout << " Pick 1: ";
cout << " Guess any number from 0 though 25, then press ENTER ";
cout << " A correct guess results in a winning of $2 ";
cout << "Pick 3: ";
cout << " Pick 1 special number from 1 through 25, but not 7 or 13 ";
cout << " Pick any 2 regular numbers from 1 through 10 ";
cout << " A correct special number guess results in a winning of $5 ";
cout << " Two correct regular number guesses result in a winning of $10 ";
cout << " A correct special number guess AND one regular number guess results in a winning of $50 ";
cout << " A correct guess of all 3 numbers results in a winning of $100 ";
return;
}
//-------------------------------------------------------------------------------
int pick1()
{
int Rpick1=1+rand()%; //assigns random number for pick 1 with range 0-25
int pick1; //assigns user's pick 1
cout << " ---------------------------------------------------------------------- ";
cout << "Enter your number for pick 1: ";
cin >> pick1;
if(Rpick1 == pick1)
{
cout<<"----------------------------- ";
cout<<" YOU WON $2! ";
cout<<"----------------------------- ";
static int winnings = 2;
return winnings;
}
else
{
cout << "Sorry, your guess was not correct." << endl;
cout << "The number was "<< Rpick1 << endl;
return 0;
}
}
//-------------------------------------------------------------------------------
int pick3()
{
int Rpick3n1= 1 + rand(); //assigns random number for pick 3 first number, range 1 through 10
int Rpick3n2= 1 + rand(); //assigns random number for pick 3 second number, range 1 through 10
int Rpick3Special; //sets up the random special number
srand(time(NULL)); //seeds the random number
do
{
Rpick3Special = 1+ rand()%; //assigns random number for pick 3 special number, range 1 though 25
}
your code:
while(Rpick3Special == 7 && Rpick3Special == 13); //finds random number again if it is 7 or 13
proposed code:
while(Rpick3Special == 7 || Rpick3Special == 13); //it is "or" not "and"
int pick3n1; //assigns user's pick 3 regular number 1
int pick3n2; //assigns user's pick 3 regular number 2
int pick3Special; //assigns user's pick 3 special number
cout << " Time for pick 3! ";
cout << "Pick your first regular number: ";
cin >> pick3n1 ;
cout << "Pick the second regular number: ";
cin >> pick3n2 ;
cout << "Now pick the special number: ";
cin >> pick3Special;
cout << endl;
cout << "Here are the numbers: "<cout << "The 1st number was "<< Rpick3n1 << endl;
cout << "The 2nd number was "<< Rpick3n2 << endl;
cout << "The special number was "<< Rpick3Special << endl;
if((Rpick3n1 == pick3n1)&&(Rpick3n2 == pick3n2)&&( Rpick3Special == pick3Special))
{
cout << "---------------------------- ";
cout << " YOU WON $100!";
cout << "---------------------------- ";
return 100;
}
else if((Rpick3n1 == pick3n1)&&( Rpick3Special == pick3Special))
{
cout << "---------------------------- ";
cout << " YOU WON $50! ";
cout << "---------------------------- ";
return 50;
}
else if((Rpick3n2 == pick3n2)&&( Rpick3Special == pick3Special))
{
cout << "---------------------------- ";
cout << " YOU WON $50! ";
cout << "---------------------------- ";
return 50;
}
else if((Rpick3n1 == pick3n1)&&(Rpick3n2 == pick3n2))
{
cout << "----------------------------- ";
cout << " YOU WON $10! ";
cout << "----------------------------- ";
return 10;
}
else if((Rpick3n1 == pick3n1)||(Rpick3n2 ==pick3n2))
{
cout << "------------------------------------------- ";
cout << " Congrats, you matched a regular number! ";
cout << " But it does not qualify as a win. ";
cout << "------------------------------------------- ";
return 0;
}
else if( Rpick3Special == pick3Special )
{
cout << "------------------------------ ";
cout << " YOU WON $5! ";
cout << "------------------------------ ";
return 5;
}
else
{
cout << " Sorry no matching numbers. ";
return 0;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.