我不太確定while(選擇== 1 ||選擇== 2); 任何人都可以解釋。我明白了這一點C++「while」說明
if(choice ==1)
displayMonthly(rainfall);
else if(choice == 2)
displayTotal(rainfall);
我只是不明白此後的代碼。任何人都可以向我解釋一下。
int main()
{
//declare variable and array
int choice = 0;
double rainfall[12] = {0.0};
//get rainfall amounts
for(int x =0;x<12;x++)
{
cout << "Enter rainfall for month "<< x+1<< ": ";
cin >> rainfall[x];
}
do
{
//display menu and get menu choice
cout <<endl;
cout << "1 Display monthly amounts" << endl;
cout << "2 Display total amount" << endl;
cout << "3 End program" << endl;
cout << "Enter your choice : ";
cin >> choice;
//call appropriate function or end program
if(choice ==1)
displayMonthly(rainfall);
else if(choice == 2)
displayTotal(rainfall);
}while (choice == 1 || choice ==2);
return 0;
}
這是下一次迭代或不循環基於'choice'值的條件。 – Mahesh