#包括
using namespace std;
int
main ()
{
int multiple;
cout << "Please give a number you want to check the multiple of: ";
cin >> multiple;
if ((multiple % 5 == 0), (multiple % 2 == 0));
{
cout << multiple << " is multiple of five. " << endl;
cout << multiple << " is the multiple of two. ";
}
else {
cout << multiple << " is not multiple of five. " << endl;
cout << multiple << " is not the multiple of two. ";
}
return 0;
}
我在代碼中找不到錯誤。它在 else 陳述句中顯示錯誤。我在代碼中找不到錯誤。它在 else 陳述句中顯示錯誤。我在代碼中找不到錯誤。它在 else 陳述句中顯示錯誤。我在代碼中找不到錯誤。它在 else 陳述句中顯示錯誤。我在代碼中找不到錯誤。它在 else 陳述句中顯示錯誤。我在代碼中找不到錯誤。它在 else 陳述句中顯示錯誤。我在代碼中找不到錯誤。它在 else 陳述句中顯示錯誤。我在代碼中找不到錯誤。它在 else 陳述句中顯示錯誤。
uj5u.com熱心網友回復:
您有語法錯誤
if ((multiple % 5 == 0), (multiple % 2 == 0));
^ ^
它應該是
if ((multiple % 5 == 0) || (multiple % 2 == 0))
uj5u.com熱心網友回復:
它在 else 陳述句中顯示錯誤,因為 C 不考慮您的 if 陳述句。C 會忽略您的“if”,因為您以分號 (;) 結束它。當 C 看到一個 ' ; ' 你的 if 陳述句沒有效果 - 它只是跳過它。此外,您的 if 語法是錯誤的。它不應該有逗號 (, )。
這是你打算做的:
if (multiple % 5 == 0 && multiple % 2 == 0) {
cout << multiple << " is a multiple of five. " << endl;
cout << multiple << " is a multiple of two. ";
}
else {
cout << multiple << " is not a multiple of five. " << endl;
cout << multiple << " is not a multiple of two. ";
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/515312.html
標籤:C
上一篇:派生類訪問基類中的私有靜態成員