Computer Science Canada

Open a text file, Read each # on a line then goes on next line to read, match # to 3 generated #'s equals or not equals

Author:  xBloodyHeartx [ Mon Oct 10, 2016 12:22 pm ]
Post subject:  Open a text file, Read each # on a line then goes on next line to read, match # to 3 generated #'s equals or not equals

What is it you are trying to achieve?
i have a text file with random numbers in it (ex. 1 10 14 next line 1 7 14 next line 2 4 8 and so forth.) The main program generates 3 random numbers without repeated numbers (ex. 1 12 23 correct ... 11 22 22 wrong). So question is how can i open up the text file in my main program to read each number from one line (one line gives you 3 numbers) then goes next line to read another set of each numbers and so forth unlimited lines. then need to match it with my generated 3 numbers i created to the numbers in my text file. if generated numbers is the same on the text file it regenerates another 3 numbers, if it doesn't match on the text file then prints out on the screen the 3 generated numbers and exits the program.

main program
3 generated random numbers have 3 variables to it.
var num1, num2, num3 : int

open the text file
text file
1 10 14 => reads one number to one variable total of 3 variables, then goes next line and reads those numbers and so forth.
1 7 14
2 4 8
5 13 19
.
.
unlimited lines

match the numbers in the text file to the main program that generates 3 random numbers.
if match text file = 3 random numbers ..... it regenerates 3 random numbers
if match text file not= 3 random numbers .... it prints out on screen the 3 generated random numbers


What is the problem you are having?
Don't know how to start it off to create this program, and to find out if it is working or not.
Need to know how to start off for opening file, reading it to match the 3 generated numbers and if so regenerates another 3 numbers, if not prints it on the screen.
I have created and working well generating 3 random numbers without repeating the same numbers for 3 numbers. Just the text file part i am stuck at.

the code is really long, so hoping if you guys can guide me or show a little code for the open text file, read the numbers and matching it.

Author:  The one they call Greed [ Thu May 25, 2017 12:01 pm ]
Post subject:  RE:Open a text file, Read each # on a line then goes on next line to read, match # to 3 generated #\'s equals or not equ

first you need to get the 3 random numbers and set the perimeters for each one, check each time a new one is generated to see if it matches a previous one, if so, re-roll the numbers.

Second, you need to get a text file to read, make 2 variables, one for the file and one for whats in the file. As a starting point:

Turing:

var file : int
var numbers : int
open : file, "numbers.txt",get
loop
exit when eof (file)
get : file, numbers
end loop


That's just to start you off, see what you can do with that information

Author:  TokenHerbz [ Mon May 29, 2017 5:16 am ]
Post subject:  RE:Open a text file, Read each # on a line then goes on next line to read, match # to 3 generated #\'s equals or not equ

eof is end of file (textFile)..

within that loop thats what you want to check for, personally but not required, there are functions that are better for reoccurring codes... id suggest aiming for that if you wanna make your teacher happy....

since softward development afterall is, open source and use friendly... he would like that. is my guess...

name it something appropriate...


: