Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

anonymous3025

macrumors newbie
Original poster
May 2, 2008
6
0
I wrote a non GUI simple calculator app in C. Here is the code.

Code:
#include <stdio.h>
main()
{
	float num1;
	float num2;
	char oper;
	float ans;
	printf("Enter an equation\n");
	scanf("%f%c%f\n" , &num1, oper, &num2);
	switch (oper)
	{ case ('+') :		//Case for addition
		ans=num1+num2;
		printf("The answer is %f\n" , ans);
	
	
	 case ('-') :		//Case for subtraction
		ans=num1-num2;
		printf("The answer is %f\n" , ans);
	
	
	 case ('*') :		//Case for multiplication
		ans=num1*num2;
		printf("The answer is %f\n" , ans);
	
	
	 case ('/') :		//Case for division
		ans=num1/num2;
		printf("The answer is %f\n" , ans);
		
		break;
		default :
		printf("\aThat is not an allowed operation\n");
	}
}


How would I be able to analyze certain characters in an NSTextField so I could make this a GUi in Cocoa with an NSTextField where the equation is entered and another NSTextField where the answer is displayed. Any help will be much appreciated.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.