Help for how to read more than one line from text file with intergers in it. 
	 
	
		| Author | 
		Message | 
	 
		 
		xBloodyHeartx
 
 
 
    
		 | 
		
		
			
				  Posted: Mon Mar 04, 2013 12:41 pm    Post subject: Help for how to read more than one line from text file with intergers in it.  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				What is it you are trying to achieve?
 
I am trying to read more then one line from a text file into my program.
 
 
What is the problem you are having?
 
It reads the last line only and makes sure the random number generated doesn't match that 
 
which it does when it outputs to the screen, but it still shows the first line from the 
 
file in my output when generating the numbers to the screen.
 
My text file has and shows in notepad like this
 
2   4
 
3   4
 
I know how to write to a file and add to existing file as well.
 
 
Describe what you have tried to solve this problem
 
I have tried searching through this forums and google search as well, but still can't get 
 
it to read from the first line make sure it doesn't match before going to next line to 
 
make sure it doesn't match either.
 
 
 
Post any relevant code (You may choose to attach the file instead of posting 
 
the code if it is too long)
 
	  | Turing: | 	 		  
var hi1, hi2  : int
var menuinput  : int
var ch  : string (1)
var file  : int
var winningnumbers1, winningnumbers2  : int := 0
var linenumber  := 0
var tot2hi4lo  : int
var linex  : int
loop
    cls
    put "3. high and low"
    put "4. exit"
    get menuinput
     if menuinput  = 3 then
        cls
        locate (1,  1)
        put "how many lines"
        get linex
         var lines2h4l  : array 0 .. linex  of int
%Open the file here early
        open : file,  "D:/Winnings.txt", get
        for linez2h4l  : 1 ..  upper (lines2h4l )
            loop
                loop
                    loop
                        hi1  := Rand.Int  (1,  4)
                        hi2  := Rand.Int  (1,  4)
                        if hi1  not= hi2
                                 and hi2  not= hi1
                                 then
                            exit
                        end if
                    end loop
                    var d  : int := 0
                    var sure  : boolean := false
                    loop
                        if hi1 > hi2  then
                            d  := hi1
 
                            hi1  := hi2
 
                            hi2  := d
 
                            sure  := false
                        end if
                        exit when sure
 
                        sure  := true
                    end loop
                    tot2hi4lo  := hi1 + hi2
                     if tot2hi4lo >=  3 and tot2hi4lo <=  7 then
                        exit
                    end if
                end loop
%Trying to read the file here to make sure my generated numbers don't match
                loop
                    exit when eof (file )
                    get : file, winningnumbers1, winningnumbers2
                 end loop
                if (winningnumbers1  xor winningnumbers2 ) not=  (hi1  xor hi2 ) then
                    exit
                end if
            end loop
            locate (11 + linez2h4l,  1)
            color (36)
            put " ", hi1,  " ", hi2,  "  = ", tot2hi4lo
             color (16)
            put "----------------------------------------------------------------"
        end for
%Close the file at this point        
        close : file
        
         color (1)
        put "Back To The Menu, Hit Enter"
        getch (ch )
    end if
    if menuinput  = 4 then
        exit
    end if
end loop
  | 	  
 
Please specify what version of Turing you are using
 
Turing 4.1.2 | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
		 
		Sponsor Sponsor 
		 
  
		 | 
		
 | 
	 
	 
		  | 
	 
				 
		Tony
 
  
 
    
		 | 
		
		
			
				  Posted: Mon Mar 04, 2013 3:18 pm    Post subject: Re: Help for how to read more than one line from text file with intergers in it.  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				xBloodyHeartx @ Mon Mar 04, 2013 12:41 pm wrote: 
 
I am trying to read more then one line from a text file into my program.
 
 
 
It does read more than one line. That's how it gets to the last line... That is, then you open a file, the reading starts at the beginning.
 
 
Also
 
Quote: 
 
for linez2h4l : 1 .. upper (lines2h4l) 
 
 
            loop 
 
                loop 
 
                    loop 
 
 
 
What? This seems awfully complicated. When you use exit, how do you keep track which of the 4 nested loops actually terminates? | 
			 
			
				 
Tony's programming blog. DWITE - a programming contest. | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		xBloodyHeartx
 
 
 
    
		 | 
		
		
			
				  Posted: Mon Mar 04, 2013 6:41 pm    Post subject: RE:Help for how to read more than one line from text file with intergers in it.  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| okay. Tony then where should i open the file in order it to read the numbers in that file making sure from first line to end of file it doesnt generate random numbers that are equal to those numbers in the file? i want it to work for every line in that file not just the last line, because it still outputs the numbers on the first line from the file on the screen. It shouldn't at all. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		xBloodyHeartx
 
 
 
    
		 | 
		
		
			
				  Posted: Mon Mar 04, 2013 6:43 pm    Post subject: RE:Help for how to read more than one line from text file with intergers in it.  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| Also Tony trying to put that if statement for it to not equal from generated numbers to the numbers in the file. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		Tony
 
  
 
    
		 | 
		
		
			
				  Posted: Mon Mar 04, 2013 8:07 pm    Post subject: RE:Help for how to read more than one line from text file with intergers in it.  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| Alright, where in the program are you reading data from a file? What action does the program execute immediately after reading the first line of input? Talk about that in detail, it should point you towards the answer to your questions. | 
			 
			
				 
Tony's programming blog. DWITE - a programming contest. | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		xBloodyHeartx
 
 
 
    
		 | 
		
		
			
				  Posted: Tue Mar 05, 2013 10:58 am    Post subject: RE:Help for how to read more than one line from text file with intergers in it.  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| So, Tony it will work though right? i just have to figure out what you said to find my answer cause i don't want to switch to c/c++ one of my friend is saying so that he can help me lol. He doesn't know turing. I chose turing because it was fast to write one and simple then c/c++. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		Insectoid
 
  
 
    
		 | 
		
		
			
				  Posted: Tue Mar 05, 2013 8:53 pm    Post subject: RE:Help for how to read more than one line from text file with intergers in it.  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Quote: He doesn't know turing.  
 
 
If he's a half-decent programmer capable of doing anything in C++, it won't matter that you're using Turing. | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		 | 
	 
 
	
	
	 
	
	 |