Why is my code not working and why is the compiler throwing a "numberone undeclared" and a "numbertwo undeclared" message on the two scanf lines? I have definitely declared the variables!
Code:#import <Foundation/Foundation.h> #import <stdio.h> @interface calculator : NSObject { int numberonetomultiply; int numbertwotomultiply; int numberone; int numbertwo; int result; } -(void) disp; -(void) setnumberone: (int) numberone; -(void) setnumbertwo: (int) numbertwo; -(void) runcalc; @end @implementation calculator -(void) disp { printf("\n%i multiplied by %i yields %i\n", numberonetomultiply, numbertwotomultiply, result); } -(void) setnumberone: (int) numberone { numberonetomultiply = numberone; } -(void) setnumbertwo: (int) numbertwo { numbertwotomultiply = numbertwo; } -(void) runcalc { result = (numberonetomultiply * numbertwotomultiply); } @end int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSLog (@"This program is a calculator that multiplies two numbers."); NSLog (@"Input first number,then press enter\n"); calculator *humaninput = [calculator new]; scanf ("%i", &numberone); printf("Now type the second number, then press enter\n"); [humaninput setnumberone: numberone]; scanf ("%i", &numbertwo); [humaninput setnumbertwo: numbertwo]; [humaninput runcalc]; printf("\nDisplaying answer...\n"); [humaninput disp]; [pool drain]; return 0; }



LinkBack URL
About LinkBacks


