Help with a fractions program 
	 
	
		| Author | 
		Message | 
	 
		 
		poly
 
 
 
    
		 | 
		
		
			
				  Posted: Sun Mar 30, 2003 9:33 pm    Post subject: Help with a fractions program  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				Hey guys, Im pretty new to turing and new to these boards and I am in need of help for a program that we wrote in class the other day. The teacher handed us a few problems and told us to write them up, we didnt have to, but they were extra practice. Anywho I got stumped on this one question. What we need to do is write a program (in turing of coarse) that will add 2 fractions that the user inputs and than outputs the answer. well that was easy, heres my code for it
 
	  | code: | 	 		  % All the program variables
 
var fTop, fBottom, sTop, sBottom : int
 
 
% Now getting the 2 fractions from user
 
put "Enter the first fraction (enter Numerator, space, enter denominator) " ..
 
get fTop, fBottom
 
put "Enter the second fraction (enter Numerator, space, enter denominator) " ..
 
get sTop, sBottom
 
 
% Spacer
 
put ""
 
 
% This will show the user their 2 fractions with a '+' between the 2
 
put fTop, "/", fBottom, " + ", sTop, "/", sBottom
 
 
% This will add the 2 fractions and output answer
 
put "= ", (fTop * sBottom) + (sTop * fBottom), "/", (fBottom * sBottom)
 
  | 	  
 
 
so say the user inputs 3/4 and 5/12 it would look like...
 
3/4 + 5/12 = 56/48
 
 
Now how would I write something to round the fraction? would i use IF statement... could somebody (if you have some free time) pelase write me what I would put for the program to round the fraction if the fraction could be rounded | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
		 
		Sponsor Sponsor 
		 
  
		 | 
		
 | 
	 
	 
		  | 
	 
				 
		Blade
 
 
 
    
		 | 
		
		
			
				  Posted: Sun Mar 30, 2003 9:41 pm    Post subject: (No subject)  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				no, you would use round(), it rounds up no matter what the decimal is, but if you want to round down... then you use floor()
 
ex:
 
	  | code: | 	 		  put round(24+15)
 
put floor(24+15)
 
  | 	  
 
but in this case you dont need to round an addition question, but thats how you would use it | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		poly
 
 
 
    
		 | 
		
		
			
				  Posted: Sun Mar 30, 2003 9:52 pm    Post subject: (No subject)  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| Oh ok well thats what I thought I had to do, but my teacher said that it wouldnt be correct.. So i was like "wtf is he talkin about"... thanks for the reply | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		Tony
 
  
 
    
		 | 
		
		 | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		Blade
 
 
 
    
		 | 
		
		
			
				  Posted: Sun Mar 30, 2003 10:29 pm    Post subject: (No subject)  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| i think i misunderstood the question... i thought he wanted to round the top number... so if he got 2.5/4 then he wanted it as 2/4(1/2) or 3/4 or something like that... you see what i mean? | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		poly
 
 
 
    
		 | 
		
		
			
				  Posted: Mon Mar 31, 2003 12:16 pm    Post subject: (No subject)  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| just what Im looking for Tony, thanks. I had it written similiar to what you have, except for i didnt have the 2.. numftop, thanks guys | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		 | 
	 
 
	
	
	 
	
	 |