Random Numbers question

Generate a user numbered set of random numbers

Page 1 of 1

6 Replies - 1834 Views - Last Post: 05 December 2010 - 09:02 PM Rate Topic: -----

#1 millertime03  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-November 10

Random Numbers question

Posted 05 December 2010 - 07:53 PM

The problem statement is to develop a lottery function that will draw numbered balls from 1 to 10. Assume that 3 balls are drawn at random. Allow the user to enter the number of lottery drawings to simulate. Calculate and print the percentage of the time the result contain 3 even numbers in the simulation. Also calculate and print the time 7 occur in the three numbers in the simulation.

I have the following code and i can get it to generate the correct amount of sets the user inputs, but i can not get it to just put 3 numbers in each set. it wil give and answer similar to 345, 2345, 1234, 224 and 2345, for a user input of 5. but i need just 3 numbers per set. Any advice would be appreciated.

Thanks Miller.




void Lottery(int x)
{
	int random_integer, user_input, lowest=1, highest=10, range=(highest-lowest)+1;
	cout << "How many times would you like me to simulate the lottery drawing:  ";
	cin >> user_input;

	for (int index = 0; index < user_input; index++)
	{
		random_integer = lowest + int (range*rand());
			(RAND_MAX +1);
		cout << random_integer << endl;
	}


  /*cout << "                              Operations \n " << endl; 
	cout << "1. Temperature Conversion Celsius to Fahrenheit" << endl;
	cout << "2. Salary Calculator" << endl;
	cout << "3. Print A Hollow Square" << endl;
	cout << "4. Estimate The Value Of Pi" << endl;
	cout << "5. Lottery Drawing" << endl;
	cout << "6. Exit Program \n\n" << endl;

	cin >> program; */
	return;
}

This post has been edited by NickDMax: 05 December 2010 - 10:30 PM
Reason for edit:: added code tags: [code] -- paste your code here -- [/code]


Is This A Good Question/Topic? 0
  • +

Replies To: Random Numbers question

#2 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1335
  • View blog
  • Posts: 4,575
  • Joined: 19-February 09

Re: Random Numbers question

Posted 05 December 2010 - 08:12 PM

Here is another way of Producing Random Numbers for you to look at.
Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2957
  • View blog
  • Posts: 10,181
  • Joined: 08-August 08

Re: Random Numbers question

Posted 05 December 2010 - 08:18 PM

First, use code tags!!!

Second, the code you show will output N random numbers where N is supplied by the user. My guess is that you want to return numbers perhaps in a two dimensional array with three random numbers selected N times, but that's impossible to know given the limited information you've provided.
Was This Post Helpful? 0
  • +
  • -

#4 millertime03  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-November 10

Re: Random Numbers question

Posted 05 December 2010 - 08:39 PM

View PostCTphpnwb, on 05 December 2010 - 07:18 PM, said:

First, use code tags!!!

Second, the code you show will output N random numbers where N is supplied by the user. My guess is that you want to return numbers perhaps in a two dimensional array with three random numbers selected N times, but that's impossible to know given the limited information you've provided.





Ok This is my first semester of this so not to sound stupid but what do you mean by code tags? I also don't have any other info to give you because this is all he gave me. Our teacher has also not told us about how to do arrays. Thanks
Was This Post Helpful? 0
  • +
  • -

#5 millertime03  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-November 10

Re: Random Numbers question

Posted 05 December 2010 - 08:45 PM

If you need to know something else or have a question just ask I dont mind answering it to the best of my knowledge.
Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2957
  • View blog
  • Posts: 10,181
  • Joined: 08-August 08

Re: Random Numbers question

Posted 05 December 2010 - 08:52 PM

[code ]code tags allow code to retain indenting and some highlighting![/code ]

Remove spaces to use them. Read the rules for more info.

If you aren't going to use arrays, the you'll want to output three random numbers each time you go through the loop instead of one.
Was This Post Helpful? 0
  • +
  • -

#7 millertime03  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-November 10

Re: Random Numbers question

Posted 05 December 2010 - 09:02 PM

Oh ok gotcha. ok I'll give it another try tomorrow thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1