Plz help with project!
Author |
Message |
Mak
|
Posted: Sun Apr 13, 2008 7:42 pm Post subject: Plz help with project! |
|
|
I need to know how to store random numbers from 0 - 9 in an array with no repeats and output them in random order for my project.
My coding is:
" %Variable declaration
var intnum : array 0 .. 9 of int
var inttemps : array 0 .. 9 of int
var intswitch : int
var intrand : int
var intrand3 : int
var inttemp : int
var intrand2 : int
var intcounter : int
var intcount : int
var inttrack : int
colorback (1)
cls
color (3)
%variable initialization
intcounter := 0
intcount := 0
for i : 0 .. 9
intnum (i) := 0
end for
for i: 0 .. 9
inttemps(i) := 0
end for
%processing stage
for i : 0 .. 9
loop
randint (intrand, 0, 9)
exit when intnum (intrand) = 0
end loop
intnum (intrand) := 1
end for
for i : 0 .. 9
if intnum (intrand) = 1 then
put i, " "..
end if
end for
locate (2, 1)
put "Up to which number would you like to reverse?"
loop
get intswitch
var intstore : array 0..intswitch of int
for decreasing i: intswitch .. 0
if intnum(i) = 1 then
put i, " "..
end if
end for
inttemp := intswitch + 1
for i : inttemp .. 9
if intnum (i) = 1 then
put i, " " ..
end if
end for
intcount := intcount + 1
end loop
for i : inttemp .. 9
if intnum (i) = 1 then
put i, " " ..
end if
end for
for i : 0 .. 9
if inttemps (intrand) = 1 then
put i, " "..
end if
end for
locate (2, 1)
put "Up to which number would you like to reverse?"
loop
get intswitch
var intstore : array 0..intswitch of int
for i: 0..intswitch
if intnum(i) = 1 then
put i, " "..
end if
end for
inttemp := intswitch + 1
for i : inttemp .. 9
if intnum (i) = 1 then
put i, " " ..
end if
end for
intcount := intcount + 1
end loop
for i : inttemp .. 9
if intnum (i) = 1 then
put i, " " ..
end if
end for
"
The program is supposed to show the digits 0 through 9 in a random order, then the user can input a number, and the number entered reverses the order of the numbers outputted. The object is to have all the numbers in numerical order.
Thanks! |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
A.J
![](http://compsci.ca/v3/uploads/user_avatars/119833057151651227b0d87.gif)
|
Posted: Sun Apr 13, 2008 8:32 pm Post subject: Re: Plz help with project! |
|
|
so...everytime the user inputs ANY number, it just reverses the numbers in the array?
I don't think I follow you....could you please tell me what you want again
And to fill the array from 0-9 randomly, just do the following:
[deletia] Edit by Clayton: We don't just do the work for the person, help them find the solution, don't just hand it to them on a silver platter
This first gets a random value between 1 and 9.
If the random value has not been 'used' before, then store it in the array at position 'i'. |
|
|
|
|
![](images/spacer.gif) |
Mak
|
Posted: Sun Apr 13, 2008 8:58 pm Post subject: Re: Plz help with project! |
|
|
That's all I needed.
Thank you for your help! |
|
|
|
|
![](images/spacer.gif) |
|
|