Complete a program that utilizes random number generators (1 point) to play number guessing games with the user. The user has two game choices- Pick1 (1 point) and Pick3 (2 points). The table below details the rules for each game. The program should allow the user to continue playing unless the user has won $100 or ore already, or the user wishes to end the program (2 points). The program should produce a report indicating the "total winning prizes" as well as "subtotal prizes" from each game (e.g. one for Pick1 and one for Pick3) (2 points). Use at least three different functions besides the main function to complete this assignments (2 points).
For Pick1: the user enters one number within the range 0-25 and wins $2
[I already did the program for this one]
I just need help with the second portion of my assignment which is:
For Pick3: the user enter 2 regular numbers and one special number.
-reg. number range 1-10
-special number range 1-25 (except 7 & 13)
$5 if only special number matched
$10 if two reg. numbers matched
$50 if one reg. number AND the special number matched
$100 if all numbers matched
Here is what I have so far:
#include<iostream>
#include<ctime> //for time functions
#include<cstdlib> //for srand and rand
using namespace std;
double Pick1();
double Pick3();
//double totalWins();
void main()
{
cout<<"Pick 1:"<<endl;
cout<<"----------------"<<endl;
static double winnings = 0;
winnings += Pick1();
cout<<"Your winnings for \"Pick 1\" is: $ "<< winnings <<endl;
cout<<endl;
cout<<"Pick 3:"<<endl;
cout<<"----------------"<<endl;
static double winnings3 = 0;
winnings3 += Pick3();
cout<<endl;
cout<<"Your winnings for \"Pick 3\" is: $ "<< winnings3 <<endl;
//cout<<"Total amount winnings is: $ "<< totalWins() <<endl;
}
double Pick1()
{
srand(static_cast<unsigned int> ((0)));
//double w;
double randNum=rand()%26;
double userNum=rand()%26;
cout<<"Enter a number between 0-25:";
cin>>userNum;
srand(userNum);
if(randNum == userNum)
{
cout<<"-----------------------------…
cout<<" !!!!You Won $2.00!!!!\n";
cout<<"-----------------------------…
cout<<endl;
return 2;
}
else
{
cout<<"You lost"<<endl;
cout<<"The number was "<< randNum<<endl;
return 0;
}
}
double Pick3()
{
srand(static_cast<unsigned int> ((0)));
double randNum=rand()%11;
double userNum=rand()%11;
double userNum2=rand()%11;
double specNum=rand()%26;
cout<<"Enter two numbers between 1-10:"<<endl;
cout<<"first number: ";
cin>>userNum;
cout<<"second number: ";
cin>>userNum2;
cout<<"Now enter a special number between 1-25:"<<endl;
cin>>specNum;
srand(userNum);
srand(userNum2);
srand(specNum);
if(randNum == specNum)
{
cout<<"-----------------------------…
cout<<" !!!!You Won $5.00!!!!\n";
cout<<"-----------------------------…
return 5;
}
if((randNum == userNum)&&(randNum == userNum2))
{
cout<<"----------------------------…
cout<<" !!!!You Won $10.00!!!!\n";
cout<<"----------------------------…
return 10;
}
if((randNum == userNum)&&(randNum == specNum))
{
cout<<"---------------------------…
cout<<" !!!!You Won $50.00!!!!\n";
cout<<"---------------------------…
return 50;
}
if(randNum == userNum)&&(randNum == userNum2)&&(randNum == specNum))
{
cout<<"---------------------------…
cout<<" !!!!You Won $100.00!!!!\n";
cout<<"---------------------------…
return 100;
}
else
{
cout<<"You lost"<<endl;
cout<<"The number was "<<randNum<<endl;
return 0;
}
}
}
double totalWins()
{
double total, total1, total2, winnings=0;
total1= winnings += Pick1();;
total2= winnings += Pick3();;
total = total1 + total2;
system ("PAUSE");
return total;
}
This post has been edited by stayscrisp: 18 October 2011 - 07:45 AM
Reason for edit:: Please use code tags when posting code!

New Topic/Question
Reply



MultiQuote





|