This Objective C tutorial will hep you to build easy calculator in command line tool, its easy to understand
NOTE: You can change the variable names as you want. In this coding I have used number1, number2 and method as variables
float number1, number2;
int method;
NSLog(@"Enter 1(addition) or 2(subtraction) or 3(division) or 4(multiplication)");
scanf ("%i", &method);
NSLog(@"enter two number with spaces between them");
scanf("%f", &number1);
scanf ("%f", &number2);
switch (method) {
case 1:
NSLog(@"the sum of number %f and %f is %f", number1, number2, number1+number2);
break;
case 2:
NSLog(@"the subtraction of number %f and %f is %f", number1, number2, number1-number2);
break;
case 3:
NSLog(@"the division of number %f and %f is %f", number1, number2, number1/number2);
break;
case 4:
NSLog(@"the multiplication of number %f and %f is %f", number1, number2, number1*number2);
break;
default: NSLog(@"enter a specific number");
break;
0 comments:
Post a Comment