I am trying to learn objective C with my brother and I have stumbled onto a problem involving one trying to collect a user's input and checking if it is odd or even.
I made this, and this works to test if a number is even or odd:
#include <stdio.h>
int main(){
int num = 22;
if (num % 2 == 0)
{
printf("Yep. ");
}
else
{
printf("Nope. ");
}
}
But how do i get it so that I can take what a user input is and run it to see if it is even or odd?
This is what I have so far:
#include <stdio.h>
int main(){
int num = 0;
printf("Enter your string: ");
scanf("%s", num);
printf("Your string is %s\n", num);
if (num % 2 == 0)
{
printf("Yep. ");
}
else
{
printf("Nope. ");
}
}