Sending values to a control

This is a discussion on Sending values to a control within the C Programming forums, part of the General Programming Boards category; Hey guys I'm really new to C coding, only been doing it a day or so... but i'm trying to ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    7

    Sending values to a control

    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

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Ok, this is C how again?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    7
    Haha hmm, well it's Objective-C using Cocoa, I guess it's not standard C the way you're used to it...

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,069
    Well, I'd be willing to bet if this forum was called "Objective-C using Cocoa" alot of people wouldn't be here.

    Your switch statement looks alright, anyway.
    Sent from my iPadŽ

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Of course you may want to add a check to make sure you don't divide by zero.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Dec 2005
    Posts
    7
    No, the switch statement is fine,

    It's just the statement i'm using to TRY and send 3 values to my calculation controller....

    Code:
    	totals = [Calculate: number1 number2 type]; // This is clearly where it's going wrong :/
    that bit. I'm basically trying to say "on the function named "Calculate" send it 3 values, number1, number2 and type."

    How would you do that in ANSI C?

  7. #7
    Registered User
    Join Date
    Dec 2005
    Posts
    7
    Woo hoo I got it!

    incase anyone cares:

    Code:
    totals = [calculation calculateValue:number1 with:number2 calcType:type];
    is the cocoa way to send values to a controller :P it probably means nothing to any of you though :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Casting a struct for sending to socket
    By chrisjmoss in forum Networking/Device Communication
    Replies: 6
    Last Post: 04-08-2008, 09:11 AM
  2. tab control
    By tyouk in forum Windows Programming
    Replies: 6
    Last Post: 02-07-2005, 10:47 PM
  3. Replies: 1
    Last Post: 02-03-2005, 02:33 AM
  4. Edit Control problem
    By Malek in forum Windows Programming
    Replies: 3
    Last Post: 06-16-2002, 01:12 AM
  5. Updating Static Control Color Real-Time :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-29-2002, 03:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21