Hey all, I'm having a bit of trouble with if and else. I am supposed to make this program that asks the user to enter an even number. If the number is even, it is supposed to reply, "Thanks!" If the number is odd, it is supposed to ask for an even number again. If the user enters an even number this time, the reply is once again, "Thanks!" If it is an odd number again, it is supposed to reply, "You dummy!" I am supposed to ask for 3 separated numbers not including the re prompts because the user entered in an odd number. Here's what I got:
Code:
#include <stdio.h>
#include <stdlib.h>
//Prototype
void getEven(int number);
int main()
{
int number;
getEven(number);
getEven(number);
getEven(number);
return 0;
}
void getEven(int number)
{
printf("Enter an even number => ");
scanf("%d", number);
if ( number%2 == 0 ){
printf("Thanks!\n");
}
else{
printf("Enter an even number => ");
scanf ("%d", number);
}
if ( number%2 == 0 ){
printf ("Thanks!\n");
}
else{
printf("You dummy!");
}
}
As soon as I enter in the number, the program would freeze. I thought I had it right, but I'm a bit lost on what I can do. Any suggestions? Thank you guys!