0
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.
4

4 に答える 4

5
printf("Input: %f. \n", input);

代わりにこれを使用してください:

printf("Input: %d. \n", input);

f変換指定子は値を出力し、変換指定子をdouble使用して値を出力します。dint

于 2013-02-12T17:12:54.563 に答える
3

input整数型です。でお試しくださいprintf("Input: %d. \n", input);

于 2013-02-12T17:12:59.720 に答える
2

この行は正しくありません:

printf("Input: %f. \n", input);

変数inputintタイプであるため、%dフォーマットシーケンスを使用する必要があります。

printf( "入力:%d。\ n"、入力);

于 2013-02-12T17:14:20.767 に答える
0

正しい構文は次のとおりです。printf( "入力:%d。\ n"、input);

フォーマット指定子%dは整数を表します。

于 2013-02-12T17:26:19.660 に答える