Can someone please give me some guidance on this, i'm having some trouble in general about how to tackle it- this is for own personal intrest using some practice problems i found online thanks
Display six randomly generated unique whole numbers between 1 and 53 inclusive. The list must be sorted and displayed in ascending order and must contain no duplicate values.
SAMPLE OUTPUT (Softcopy):
The numerals on the left of the sample output below are there for the analyst's reference only and will not appear on the screen. Underlined items indicate values entered by the user.
3 8 12 21 22 39
SYMBOLIC CONSTANT LIST (Global):
Label Description Value Process Usage Destination
SIZE Quantity of numbers chosen 6 Loop limit ---
MAX Maximum random number value 53 Loop limit ---
LOCAL VARIABLE LIST for "main"
Label Description Source Usage Destination
PICKED MAX Integer flags indicating
which values have picked
(0 means NO, 1 means YES) Assigned Flags ---
N SIZE unique random integers
with values ranging
from 1 to MAX inclusive Random Sorted Screen
Label Description Source Usage Destination
PASS Counter of array passes Assigned Loop index ---
P General purpose counter Assigned Loop index ---
T Temporary swap variable Assigned Swapping ---
ALGORITHM for "main":
This task involves four major elements:
Selecting SIZE random integers within the range of 1 to MAX
Making sure that each integer selected is unique
Sorting the list of selected numbers in ascending order
Displaying the list of selected numbers
We can use an array named N to store the Lotto numbers that we select. Array N will be declared to have six elements, identified using subscripts 0 through 5.
One method of ensuring the selection of unique numbers involves the use of a second array named PICKED. It will use MAX integer storage locations to keep track of which numbers have been selected to prevent our program from using a duplicate value. Each element of the PICKED array will hold either a 1 or a 0 to indicate whether the associated value has been used yet. For example, the first element of PICKED would have a 0 stored in it if the number 1 had been used yet, or a 0 stored there if 1 had not yet been picked. The second element of PICKED would have a 0 stored in it if the number 2 had been used yet, or a 0 stored there if 2 had not yet been picked. (And so on..)
Remember that in C the first element of PICKED would be identified as PICKED and the the second element of PICKED would be identified as PICKED. So we must be careful to offset our use of the subscript in the PICKED array by one. In other words, the storage location that we would use to track whether the value 8 had been selected for the Lotto would be PICKED, not PICKED.
The steps below describe how to use the arrays N and PICKED to accomplish the program objectives. The italicized text below provides detailed hints about how to accomplish the steps. Before reading the hints, see if you can figure out each step on your own. Then use the hints if you need help.
Seed the random number generator to produce different numbers for each run.
In C, the command for this action is: srand(time(NULL));
Load the array PICKED with FALSE values to assert that no values have been picked yet.
Use a loop that counts with P from 0 to one less than MAX to assign zero into the element of array PICKED having the subscript P).
Load the array N with SIZE unique random numbers.
Use a loop that counts with P from 0 to one less than SIZE to:
Fill the lotto number array with unique random numbers between 1 & MAX inclusive.
Use a (nested) trailing decision loop that performs the follow body:
Select a random number between 1 & MAX inclusive
It should repeat this body as long as the flag value in the PICKED array element at the position (determined from N[P]-1) is 1 (True).
Set the flag that notes which number was picked in the previous step.
Set the flag value in the PICKED array at the position (determined from N[P]-1) to be 1 (True).
Sort the Array of Numbers using a "Bubble Sort":
Use a loop that counts with PASS from 1 to one less than SIZE to:
Pass through the elements array N and swap any pairs that are out of order.
Use a loop that counts with P from 0 to one less than SIZE-PASS to:
Test if N's element with subscript P is greater than N's element with subscript P+1. If so, swap those two values.
Use an extra (temporary) variable to retain the element that you assign to first.
Display line 1 of the sample softcopy.
Display a blank line.
Display a line showing all values of the N array, each in a width of 5.
Use a loop that counts with P from 0 to one less than SIZE to display the element of N at subscript position P (in a width of 5).
Display a carriage return.
thanks for you help guys- you're wonderful