4 Replies - 1480 Views - Last Post: 18 October 2011 - 08:45 AM Rate Topic: -----

#1 mtdf8987  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-October 11

I need help with this random number generator game.

Posted 18 October 2011 - 07:22 AM

Let me start off by saying that I am not in school & I am teaching my self C++. I know the rules say don't copy and paste homework assignments but I really want to accomplish this task. I've been having dreams about this program! So I would greatly appreciate it if someone would guide me through this program. Here are the instructions and my program:

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!


Is This A Good Question/Topic? 0
  • +

Replies To: I need help with this random number generator game.

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,735
  • Joined: 25-December 09

Re: I need help with this random number generator game.

Posted 18 October 2011 - 07:42 AM

void main() is incorrect. The function main must be defined to return an int, int main().

Third you are calling srand() several times. The srand() function should only be called once, usually at the beginning of your main function.

Quote

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)


What exactly do you not understand?

Jim
Was This Post Helpful? 0
  • +
  • -

#3 mtdf8987  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-October 11

Re: I need help with this random number generator game.

Posted 18 October 2011 - 07:50 AM

View Postjimblumberg, on 18 October 2011 - 07:42 AM, said:

void main() is incorrect. The function main must be defined to return an int, int main().

Third you are calling srand() several times. The srand() function should only be called once, usually at the beginning of your main function.

Quote

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)


What exactly do you not understand?

Jim
I need to know if I'm going the right path when using if statements. I keep getting errors.
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,735
  • Joined: 25-December 09

Re: I need help with this random number generator game.

Posted 18 October 2011 - 07:52 AM

Quote

I keep getting errors.


If you are getting compile errors, post the complete error messages exactly as they appear in your development environment.

If the program is not producing the correct output, tell us what you have inputted into the program and show what the program is outputting, and what you expect the output to be.

Jim

This post has been edited by jimblumberg: 18 October 2011 - 07:54 AM

Was This Post Helpful? 0
  • +
  • -

#5 Karel-Lodewijk  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 449
  • View blog
  • Posts: 849
  • Joined: 17-March 11

Re: I need help with this random number generator game.

Posted 18 October 2011 - 08:45 AM

Spoiler


I tried your code, ending your strings with a quote, returning int in your main and 1 mismatched bracket later it worked. Didn't try if does what it is supposed to do but it does something.

I also took the liberty of running your code through astyle, hence the indentation. Indenting your code like this makes it easier to follow the thread of logic and spot errors.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1