幫我看看哪裡錯了
#include"iostream"
using namespace std;
int main() {
int M,D,S;
while(cin >> M >> D)
S = (M * 2 + D)%3;
if (S == 2)
cout << "大吉" <<endl;
if (S == 1)
cout << "吉" <<endl;
else
cout << "普通" <<endl;
{
return 0;
}
}
幫我看看哪裡錯了
#include"iostream"
using namespace std;
int main() {
int M,D,S;
while(cin >> M >> D)
S = (M * 2 + D)%3;
if (S == 2)
cout << "大吉" <<endl;
if (S == 1)
cout << "吉" <<endl;
else
cout << "普通" <<endl;
{
return 0;
}
}
紅色地方是我幫你補充的
1. 大括號部分是因為case不止一組,若不加的話,while只會到S = (M * 2 + D)%3;就結束了
2. 加else是因為,若不加else的話,當S是2的時候,會輸出大吉、普通,這就答案就錯誤了
#include"iostream"
using namespace std;
int main() {
int M,D,S;
while(cin >> M >> D){
S = (M * 2 + D)%3;
if (S == 2)
cout << "大吉" <<endl;
else if (S == 1)
cout << "吉" <<endl;
else
cout << "普通" <<endl;
}
{
return 0;
}
}
幫我看看哪裡錯了
#include"iostream"
using namespace std;int main() { int M,D,S; while(cin >> M >> D) S = (M * 2 + D)%3; if (S == 2) cout << "大吉" <<endl; if (S == 1) cout << "吉" <<endl; else cout << "普通" <<endl; { return 0; } }
紅色地方是我幫你補充的
1. 大括號部分是因為case不止一組,若不加的話,while只會到S = (M * 2 + D)%3;就結束了
2. 加else是因為,若不加else的話,當S是2的時候,會輸出大吉、普通,這就答案就錯誤了
#include"iostream"using namespace std;int main() { int M,D,S; while(cin >> M >> D){ S = (M * 2 + D)%3; if (S == 2) cout << "大吉" <<endl; else if (S == 1) cout << "吉" <<endl; else cout << "普通" <<endl; } { return 0; }}
幫我看看哪裡錯了