jeudi 19 février 2015

do-while loop evaluating two if and else if statements. One regardless of inputs. (C)

Below is my code, basically I'm trying to get my do-while loop to run as long as the if or else if statements are evaluated as true. But every time I run it, it works except that it always prints the 2 else if statement "the value you entered is less than 1", regardless of the user input. I am completely out of ideas as to why its wrong.



int get_input(void){

int Value_1;
int status;
do{

//Ask user to enter an odd number between 1 and 9
printf("Enter any odd number between 1 and 9 inclusive> \n");
//Store entered number in Value_1

status = scanf(" %d", &Value_1);
is_valid(Value_1);
}
while (is_valid()!=1);
return(Value_1);
}

int is_valid(int status){

if(status==2 || status==4 || status==6|| status==8){

printf("The value you entered is not odd>\n");
return(0);
}
else if(status > 9){
printf("the value you entered is greater than 9> \n");
return(0);
}
else if(status < 1){
printf("the value you entered is less than 1> \n");
return(0);
}
else{
return(1);
}
}

int main(void){


int Value_1;
int status;


Value_1=get_input();
printf("%d", Value_1);
return(0);
}

Aucun commentaire:

Enregistrer un commentaire