#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
BOOL myBool = TRUE;
while (myBool == TRUE) {
int a, b, sum;
char ans;
NSLog(@"Welcome to my calculator. Type in the first number: ");
scanf("%d", &a);
check.integer <- function(a){
!length(grep("[^[:digit:]]", format(a, scientific = FALSE)))
}
check.integer(a)
NSLog(@"Type in the second number: ");
scanf("%d", &B)/>;
sum = a + b;
NSLog(@"The answer is: %d", sum);
NSLog(@"Do you want to put in another sum? (y/n)");
scanf("%s", &ans);
if (ans=='y'){
myBool = TRUE;
}
else if (ans=='n'){
myBool = FALSE;
}
while (myBool==FALSE) {
return 0;
}
}
return 0;
}
It works perfectly fine, however, I would like to be able to compare the input and if the input isn't an integer display a message that says 'Please type in an integer.'
I looked this up on some websites but I couldn't find the thing I needed. Could someone help?
AwesomeProgrammer, on 14 February 2013 - 10:09 AM, said:
Hi. I am starting out on objective C and I made this program:
It works perfectly fine, however, I would like to be able to compare the input and if the input isn't an integer display a message that says 'Please type in an integer.'
I looked this up on some websites but I couldn't find the thing I needed. Could someone help?
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
BOOL myBool = TRUE;
while (myBool == TRUE) {
int a, b, sum;
char ans;
NSLog(@"Welcome to my calculator. Type in the first number: ");
scanf("%d", &a);
NSLog(@"Type in the second number: ");
scanf("%d", &B)/>/>;
sum = a + b;
NSLog(@"The answer is: %d", sum);
NSLog(@"Do you want to put in another sum? (y/n)");
scanf("%s", &ans);
if (ans=='y'){
myBool = TRUE;
}
else if (ans=='n'){
myBool = FALSE;
}
while (myBool==FALSE) {
return 0;
}
}
return 0;
}
It works perfectly fine, however, I would like to be able to compare the input and if the input isn't an integer display a message that says 'Please type in an integer.'
I looked this up on some websites but I couldn't find the thing I needed. Could someone help?

New Topic/Question
Reply


MultiQuote


|