0

Hey guys. I am trying to figure out how to write a lottery program that will generate random numbers from 10-30 and ask the user for random numbers as well. The program should not accept numbers under 10 or above 30 from the user and the program should compare the numbers in an Array to see if the person has won or not. The program also should have 5 functions. I barely know where to go from here. Any suggestions? I just want some help because I am going to need to be really good at arrays and functions for my next semester in C++

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Clinton Portis
0

not only do you want numbers 10 thru 30, you want unique (non-repetitive) numbers. so this is how ye' can go aboot' it:

int random = 0;
int numbers[69];
bool is_included(int numbers[], int);

srand(time(NULL));

for(int i=0; i<=amount_requested; i++)
{
     //pick a random number in the range ye' desire
     random = rand()%21+10;

     //if it's not already in the array...
     if(!is_included(numbers, random))
     {
          //add it
          numbers[i] = random;
     }
     else //try again
     {
          i--;
     }
}

so, you have a little algorithm for ye' free of charge. it will load an array of with numbers from 10 to 30 with no repetition. of course, you will have to write the function definition for is_included(), but it's not that hard. if you struggle with that function, i will give it to you, but only if you first show an attempt of your own.

Edited by Clinton Portis: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.