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

  • SEARCH
  • Home
  • 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 8595553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:27:47+00:00 2026-06-12T00:27:47+00:00

Trying to write simple program on Fraction operations. Can’t compile the code. Getting an

  • 0

Trying to write simple program on Fraction operations.
Can’t compile the code. Getting an “expected identifier or ‘(‘ xcode” error in the interface around “subtract” method.

I did a research on that problem and it seems to me that it’s some sort of generic error.
Here is my program:

#import <Foundation/Foundation.h>
// Define the Fraction class
@interface Fraction : NSObject
{
int numerator;
int denominator;
}
@property int numerator, denominator;
-(void) print;
-(void) setTo: (int) n over: (int) d;
 -(double) convertToNum;
-(Fraction *) add: (Fraction *) f;
–(Fraction *) subtract: (Fraction *) f;
–(Fraction *) multiply: (Fraction *) f;
–(Fraction *) divide: (Fraction *) f;

-(void) reduce; 
@end

#import "Fraction.h"
@implementation Fraction
@synthesize numerator, denominator;
-(void) print
{
NSLog (@"%i/%i", numerator, denominator);
}
-(double) convertToNum
{
if (denominator != 0)
return (double) numerator / denominator;
else
    return NAN;
}
-(void) setTo: (int) n over: (int) d
{
numerator = n;
denominator = d;
}
// add a Fraction to the receiver

-(Fraction *) add: (Fraction *) f
{

Fraction *result = [[Fraction alloc] init];
result.numerator = numerator * f.denominator +
denominator * f.numerator;
result.denominator = denominator * f.denominator;
[result reduce];
return result;
}

-(Fraction *) subtract: (Fraction *) f
{
Fraction *result = [[Fraction alloc] init];
result.numerator = numerator * f.denominator -
denominator * f.numerator;
result.denominator = denominator * f.denominator;
[result reduce];
return result;
}

-(Fraction *) multiply: (Fraction *) f
{
Fraction *result= [[Fraction alloc] init];

result.numerator = numerator * f.numerator;
result.denominator = denominator * f.denominator;
[result reduce];
return result;

}


-(Fraction *) divide: (Fraction *) f;
{
Fraction *result = [[Fraction alloc] init];
result.numerator= numerator * f.denominator;
result.denominator = denominator * f.numerator;
[result reduce];
return result;
}

-(void) reduce
{
int u = numerator;
int v = denominator;
int temp;
while (v != 0) {
temp = u % v;
u = v;
v = temp;
}
numerator /= u;
denominator /= u;
}
@end
#import "Fraction.h"

int main (int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];


Fraction *myFraction1 = [[Fraction alloc] init];
Fraction *myFraction2 = [[Fraction alloc] init];


[myFraction2 setTo:200 over:300];

[myFraction1 setTo: 100 over: 300];




[myFraction2 subtract: myFraction1];


NSLog (@"The value of myFraction2 is:");

[myFraction2 print];

[myFraction2 release];
[myFraction1 release];

[pool drain];
return 0;
}
  • 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-06-12T00:27:48+00:00Added an answer on June 12, 2026 at 12:27 am

    Remove the comma at the end of this line in main:

    Fraction *myFraction2 = [[Fraction alloc] init], ; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a simple program to alert me when ram is getting
i'm trying to write simple tcp\ip client-server. here is server code: internal class Program
I am trying to write a simple program where i can put a HashMap
I am trying to write a simple program in C# that will read data
I'm trying to write a simple program that takes in the users input, then
I am trying to write a simple program to open a socket channel to
I'm new to Pascal and I am trying to write a simple program, but
I am trying to write a simple java program which returns me all the
I'm trying to write a simple curl program to retrieve the web page in
I'm trying to write a very simple program, I want to print out the

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.