| Author | Message | 
		 
		| baykko 
 
 
 
 
 | 
			
				|  Posted: Sat Oct 04, 2008 8:07 pm    Post subject: running total of numbers |  |   
				| 
 |  
				| This is what I have so far.  It is just the basic program that prints the numbers -100 to 100.  However, I need to have a running total of these numbers as they print. 
 
 	  | Turing: |  	  | 
var num : int :=  -100
loop
    delay (50)
    put  num : 5 . .
 
    num += 2
    exit when  num = 102
end loop | 
 
 I have tried placing totalnum+=num in various places...I get 0 as the final answer, but it does not print as a running total, and the numbers get messed up and just go in random places.
 |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
		 
		| Sponsor Sponsor
 
  
   |  | 
	 
		|  | 
				 
		| Insectoid 
 
  
 
 
 | 
			
				|  Posted: Sat Oct 04, 2008 8:09 pm    Post subject: RE:running total of numbers |  |   
				| 
 |  
				| Define 'running total'. Total of what? num and 2? |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| baykko 
 
 
 
 
 | 
			
				|  Posted: Sat Oct 04, 2008 8:11 pm    Post subject: Re: running total of numbers |  |   
				| 
 |  
				| as the numbers -100 to 100 print, there will be a total of the numbers that changes as each number is printed, so first it adds -100 and -99, and so on |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| Insectoid 
 
  
 
 
 | 
			
				|  Posted: Sat Oct 04, 2008 8:15 pm    Post subject: RE:running total of numbers |  |   
				| 
 |  
				| Use a reverse for loop. 
 
 	  | code: |  	  | 
for decreasing x: -100, 100
 %stuff in here
 end for
 
 | 
 
 Hint: use 'x' with your variable 'num'.
 |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| Clayton 
 
  
 
 
 | 
			
				|  Posted: Sun Oct 05, 2008 9:25 am    Post subject: RE:running total of numbers |  |   
				| 
 |  
				| Or just use a regular one... 
 
 	  | Turing: |  	  | for x : -100 .. 100
%stuff
 end for
 | 
 |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| Insectoid 
 
  
 
 
 | 
			
				|  Posted: Sun Oct 05, 2008 9:39 am    Post subject: RE:running total of numbers |  |   
				| 
 |  
				| Woops... Go with Clayton's idea, it'll work. Mine won't. |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| baykko 
 
 
 
 
 | 
			
				|  Posted: Sun Oct 05, 2008 7:40 pm    Post subject: Re: running total of numbers |  |   
				| 
 |  
				| well i've also used the for loop the problem is getting it to show the running total
 when i put total+=x, it just says varible has no value
 |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| Insectoid 
 
  
 
 
 | 
			
				|  Posted: Sun Oct 05, 2008 7:42 pm    Post subject: RE:running total of numbers |  |   
				| 
 |  
				| you need total := 0 at the top, and x has to be the same case as the one used to declare the for loop. |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
		 
		| Sponsor Sponsor
 
  
   |  | 
	 
		|  | 
				 
		| baykko 
 
 
 
 
 | 
			
				|  Posted: Sun Oct 05, 2008 7:45 pm    Post subject: Re: running total of numbers |  |   
				| 
 |  
				| Now it somewhat works... but i want the numbers -100 to 100 to be printed left to right... but right now they just stay on one spot 
 
 	  | Turing: |  	  | var total : int := 0
for  x :  -100 . . 100 by 2
    delay (50)
    locate (10 , 1)
    put  x : 5 . .
 
    total +=  x
    locate (20 , 30)
    put  total
end for | 
 |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| syntax_error 
 
  
 
 
 | 
			
				|  Posted: Mon Oct 06, 2008 12:31 am    Post subject: Re: running total of numbers |  |   
				| 
 |  
				| wonderful thing called 	  | code: |  	  | 
put " "
 OR
 put "/t", total [etc..]
 
 | 
 
 edit: code tags.
 |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| Clayton 
 
  
 
 
 | 
			
				|  Posted: Mon Oct 06, 2008 8:58 am    Post subject: RE:running total of numbers |  |   
				| 
 |  
				| Get rid of the locates, that is what is causing your numbers to stay in one spot. |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| [Gandalf] 
 
  
 
 
 | 
			
				|  Posted: Mon Oct 06, 2008 4:05 pm    Post subject: RE:running total of numbers |  |   
				| 
 |  
				| syntax_error, escape characters use the backslash, not the forward slash: 
 
  |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		|  |