我的條件如下:
- 如果輸入的 userIncome 的值大于 400000,則顯示錯誤。
- 同樣,如果值小于 500,則顯示錯誤。
重復回圈,直到輸入正確的值。
#define _CRT_SECURE_NO_WARNINGS
#define minINCOME 500.00
#define maxINCOME 400000.00
#include <stdio.h>
int main(void)
{
float userIncome ;
printf(" -------------------------- \n"
" Wish List Forecaster |\n"
" -------------------------- \n");
do
{
printf("Enter your monthly NET income: $");
scanf(" %.2lf", &userIncome);
if (userIncome < 500)
{
printf("ERROR: You must have a consistent monthly income of at least $500.00\n");
}
if (userIncome > 40000)
{
printf("ERROR: Liar! I'll believe you if you enter a value no more than $400000.00\n");
}
} while (userIncome >= maxINCOME && userIncome <= minINCOME);
return 0;
}
uj5u.com熱心網友回復:
對于初學者來說,這個命名常量
#define maxINCOME 400000.00
與此 if 陳述句中使用的常量不同
if (userIncome > 40000)
在這種情況下
while (userIncome >= maxINCOME && userIncome <= minINCOME);
其次對于像這樣的浮動型別的物件
float userIncome ;
您需要使用轉換說明符f而不是lf
scanf(" %f", &userIncome);
條件應該寫成
while (userIncome >= maxINCOME || userIncome <= minINCOME);
在 if 陳述句中,您需要使用定義的命名常量,例如
if (userIncome >= maxINCOME)
^^
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/424446.html
上一篇:獲取資料庫中每一列的示例資料
