Hey guys
I'm really new to C coding, only been doing it a day or so... but i'm trying to create a calculator, I've never been able to really figure a way out of doing it properly before, so I thought I might as well try
I use a Mac so i'm using Xcode with Cocoa, this is my problem... When the "EQUALS" button is pressed I want it to send 3 values to my controller which then works out what calculation to do and sends the correct value back. I'm not sure the code on how to do that works so think someone could help? I know this probably isn't the right way of doing things but I wanna sorta figure things out, make new calculators, learn new ways of doing things, etc. And this is my current one.
Ok, the code:
Code:
- (IBAction)buttonEquals:(id)sender
{
number1 = 5;
number2 = 5;
totals = [Calculate: number1 number2 type]; // This is clearly where it's going wrong :/
[totalField setFloatValue:totals];
}
That's the button that wants to send the values to the control to add the values.
Code:
#import <Cocoa/Cocoa.h>
int total;
@interface Calculate : NSObject
{
switch (type)
{
case 1:
total = number1 + number2;
break;
case 2:
total = number1 - number2;
break;
case 3:
total = number1 * number2;
break;
case 4:
total = number1 / number2;
break;
}
return total;
}
@end
And that's my feeble attempt at making the function to calculate the appropriate values.
Hope you can help!
edit: oh, i'm using fixed values for the calculations just to get the first part working correctly :P