Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Random Number Generator (Prevent Repetition, Store History of Numbers) Won't Output Numbers
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Turinger23




PostPosted: Tue Apr 17, 2012 5:58 pm   Post subject: Random Number Generator (Prevent Repetition, Store History of Numbers) Won't Output Numbers

Hello everyone. What I'm trying to do with this program is create a random number generator that generates ten numbers each time it is run, prevent it from repeating numbers already generated, and then keep those numbers in memory, via an external file, so that future runs of the program will not generate numbers generated in the past.

The problem that I am encountering is that once the screen is cleared and the phrase, "Your locker combinations for Blizmotivating are:" appears, the program does not output any of the numbers to the screen. When I stop it, the feedfback is that I stopped it while it was within the "combination ()" if function.

I have attempted to solve the problem, but have come up dry. Does anyone have any suggestions for what I should do?

This is the code:
var nfloor : int

var input : string
var count : int := 0

var combination : array 1 .. 11 of int := init (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
var fileNumber : int
var divide : int := 100

%Getting floors preferred
loop
put "This program was written for the C.H.C.I. CAS Blitzmotivation initiative."
put "Numbers produced are locker numbers for Cameron Heights Collegiate Intitute."
put ""
put "There are options for the ranges of the numbers:"
put "If you wish to get numbers:"
put "On Floor 1, press 'a' and ENTER."
put "On Floor 2, press 'b' and ENTER."
put "On Floor 3, press 'c' and ENTER."
put "On Floor 4, press 'd' and ENTER."
put ""

get input

if input = "a" then
put ""
put "Thank you for your input."
delay (1500)
cls
exit
elsif input = "b" then
put ""
put "Thank you for your input."
delay (1500)
cls
exit
elsif input = "c" then
put ""
put "Thank you for your input."
delay (1500)
cls
exit
elsif input = "d" then
put ""
put "Thank you for your input."
delay (1500)
cls
exit
else
cls
put "Your input is not an integer. Please enter an integer."
delay (1500)
put ""
put ""
end if
end loop

put "Your locker combinations for Blizmotivating are:"
put ""

% Generating locker numbers
if input = "a" then
loop
% Repeat function and random combination generation
count := count + 1
randint (nfloor, 1001, 1635)
if nfloor > 1181 and nfloor < 1301 then
count := count - 1
else
combination (count) := nfloor
% Preventing repetition of combination within same set of results
if combination (count) = combination (1) then
count := count - 1
elsif combination (count) = combination (2) then
count := count - 1
elsif combination (count) = combination (3) then
count := count - 1
elsif combination (count) = combination (4) then
count := count - 1
elsif combination (count) = combination (4) then
count := count - 1
elsif combination (count) = combination (5) then
count := count - 1
elsif combination (count) = combination (6) then
count := count - 1
elsif combination (count) = combination (7) then
count := count - 1
elsif combination (count) = combination (8) then
count := count - 1
elsif combination (count) = combination (9) then
count := count - 1
elsif combination (count) = combination (10) then
count := count - 1
else
put nfloor
end if
end if
exit when count = 10
end loop

elsif input = "b" then
loop
count := count + 1
randint (nfloor, 2001, 2735)
% open : fileNumber, "Combinations.txt", put
if nfloor > 2168 and nfloor < 2329 then
count := count - 1
else
put nfloor
end if
close : fileNumber
% exit when count = 10
end loop
elsif input = "c" then
loop
count := count + 1
randint (nfloor, 3001, 3645)
put nfloor
exit when count = 10
end loop
elsif input = "d" then
loop
count := count + 1
randint (nfloor, 4002, 4429)
put nfloor
exit when count = 10
end loop
else
put "ERROR!"
end if


<Add your code here>

[/syntax]

Please specify what version of Turing you are using
<Answer Here>
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Tue Apr 17, 2012 6:09 pm   Post subject: RE:Random Number Generator (Prevent Repetition, Store History of Numbers) Won\'t Output Numbers

Lets say we're on our first iteration.

if combination (count) = combination (1)

or, in other words:

if combination (1) = combination (1)

See the problem?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: