Amazon.com Widgets Chapter 7 exercise 2
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 21, 2013, 08:04:28 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Answers to Exercises
| | |-+  Chapter 7
| | | |-+  Chapter 7 exercise 2
Pages: [1]   Go Down
Print
Author Topic: Chapter 7 exercise 2  (Read 779 times)
sonar
Newbie
*
Posts: 8


Downloading, Please wait...






« on: March 16, 2010, 09:22:42 AM »

O.K. i just looked at other answers before posting mine...

Of course I had to go another way of everybody else...

Code: (Objective-C)
-(void) print
{
BOOL needsReduce;
int preserveNum = numerator;
int preserveDenum = denominator;
int u = numerator;
int v = denominator;
int temp;
while (v != 0)
{
temp = u % v;
u = v;
v = temp;
}
numerator /= u;
denominator /= u;

switch (u) {
case 1:
needsReduce = NO;
NSLog(@"This needs NOT a reduce");
NSLog(@"The result is %i/%i", numerator,denominator);
break;

default:
needsReduce = YES;
NSLog(@"The result is %i/%i", preserveNum,preserveDenum);
NSLog(@"This fraction needs a reduce...");
NSLog(@"The reduced result is %i/%i", numerator,denominator);
break;
}


I don't know if I've done the assignment correctly now... code seems to work!   Huh
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.