int input;
printf("Type in an odd number less than or equal to 9: \n");
int correctInput = 0;
do {
scanf("%d", &input);
if((input % 2) == 0) {
printf("You have not entered an odd number. Please try again. \n");
}
else if(input > 9 || input < 1) {
printf("Your input is not from 1 to 9. Please try again. \n");
}
else {
correctInput = 1;
}
} while(correctInput == 0);
printf("Input: %f. \n", input);
我想要做的就是将一个 1-9 的奇数整数放入输入变量中。但是,当我运行此代码并输入类似 7 的内容时,我得到
Type in an odd number less than or equal to 9:
3
Input: -1.#QNAN0.