PDA

View Full Version : How can I analyze specific letters of a string entered in a NSTextField




anonymous3025
Jun 8, 2008, 10:05 AM
I wrote a non GUI simple calculator app in C. Here is the 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.