Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7555745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:41:19+00:00 2026-05-30T11:41:19+00:00

I’m working my way through Stephan Kochan’s book on Objective C and I’ve come

  • 0

I’m working my way through Stephan Kochan’s book on Objective C and I’ve come up against a problem which I’m hoping someone can help with.

Here’s my print method from a Fraction class that I’ve been working on:

-(void) print: (BOOL) reduce {
Fraction *resultReduced = [[Fraction alloc] init];
[resultReduced setTo:numerator over:denominator];

if (denominator < 0) {
    numerator = -numerator;
    denominator = -denominator;
}    
if (reduce) {
    [resultReduced reduce];
    if (resultReduced.denominator < 0) {
        resultReduced.denominator = -resultReduced.denominator;
        resultReduced.numerator = -resultReduced.numerator;
    }
    else if (resultReduced.denominator == 1)
        NSLog (@"%i", resultReduced.numerator);
    else if (resultReduced.numerator == 0)
        NSLog (@"0");
    else if (resultReduced.numerator == resultReduced.denominator)
        NSLog (@"1");
    else if (resultReduced.numerator > resultReduced.denominator || resultReduced.numerator < 0) {
        [resultReduced improper];
        if (resultReduced.whole == 0)
            NSLog (@"%i/%i", resultReduced.numerator, resultReduced.denominator);
        else if (resultReduced.whole < 0 && resultReduced.numerator < 0) {
            resultReduced.numerator = -resultReduced.numerator;
            NSLog (@"%i %i/%i", resultReduced.whole, resultReduced.numerator, resultReduced.denominator);             
        }
        else
            NSLog (@"%i %i/%i", resultReduced.whole, resultReduced.numerator, resultReduced.denominator);
    }
    else
        NSLog (@"%i/%i", resultReduced.numerator, resultReduced.denominator);
}
else
    NSLog (@"%i/%i", numerator, denominator);

}

The problem is that if I subtract 15/4 from 2/3 I get -37/12 which I’d like to display as -3 1/12 using this message [resultReduced improper] but it doesn’t appear to work. If I change

else if (resultReduced.numerator > resultReduced.denominator || resultReduced.numerator < 0) {

to just if then it does.

Could someone please explain to me why using if works, but if else doesn’t?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:41:20+00:00Added an answer on May 30, 2026 at 11:41 am

    The “if” statement by itself will execute every time. The “else” will only execute if the “if” fails.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm trying to select an H1 element which is the second-child in its group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.