do{
cout << "Select an option from the Menu: ";
cin >> choice;
// Validate the menu selection
while ((choice < 1) || (choice > 3)){
cout << "Incorrect input!, please enter an option from 1 to 3."<<endl;
cout<<"Enter your choice: ";
cin >> choice;
}
// Processing the users choice
if (choice != 3){
// Compute conversions
switch (choice){
case 1:
cout<<""<<endl;
cout<<"You have selected to convert Fijian Dollars to Vanuatuan Vatu."<<endl;
cout<<"Enter the amount you wish to convert: ";
cin >> amount;
conversion = amount * FJD_to_Vatu_Rate;
break;
case 2:
cout<<""<<endl;
cout<<"You have selected to convert Fijian Dollars to Samoan Tala."<<endl;
cout<<"Enter the amount you wish to convert: ";
cin >> amount;
conversion = amount * FJD_to_Tala_Rate;
break;
case 3:
cout<<"Here the history will be shown"<<endl;
cout<<""<<endl;
cout<<"Do You want to perform another conversion? (Y/N) ";
cin >> repeat;
if (repeat == 'Y'){
(This is what i want to know)
}
cout<<"Thank you for using this program, goodbye!"<<endl;
return 0;
}
// Display the monthly charges
cout << fixed << showpoint << setprecision(2);
cout << "The converted amount is: " << conversion << endl;
cout <<""<<endl;
}
} while (choice != 3);
cout<<"Thank you for using this program, goodbye!"<<endl;
return 0;
}
Вышеупомянутая часть моего кода для конвертера валют, может ли кто-нибудь сказать мне, что делать в разделе, где написано «это то, что я хочу знать», чтобы программа предлагала пользователю ввести выбор, чтобы она могла обработать и используйте выбор, чтобы вычислить, используя один из других случаев.
Спасибо
Подсказка: все это уже находится в цикле do-while, так что вы можете сделать, чтобы либо прервать цикл, либо позволить ему продолжить?
Удалите условие if сверху, потому что случай 3 никогда не будет выполнен.
Эта программа вряд ли является минимальной и не соревновательной. ТАК вопросы хотят минимальный воспроизводимый пример.





Удалите ваш оператор if перед switch, потому что в этом случае case 3: никогда не будет выполняться.
do{
cout << "Select an option from the Menu: ";
cin >> choice;
// Validate the menu selection
while ((choice < 1) || (choice > 3)){
cout << "Incorrect input!, please enter an option from 1 to 3."<<endl;
cout<<"Enter your choice: ";
cin >> choice;
}
// Processing the users choice
// Compute conversions
switch (choice){
case 1:
cout<<""<<endl;
cout<<"You have selected to convert Fijian Dollars to Vanuatuan Vatu."<<endl;
cout<<"Enter the amount you wish to convert: ";
cin >> amount;
conversion = amount * FJD_to_Vatu_Rate;
break;
case 2:
cout<<""<<endl;
cout<<"You have selected to convert Fijian Dollars to Samoan Tala."<<endl;
cout<<"Enter the amount you wish to convert: ";
cin >> amount;
conversion = amount * FJD_to_Tala_Rate;
break;
case 3:
cout<<"Here the history will be shown"<<endl;
cout<<""<<endl;
cout<<"Do You want to perform another conversion? (Y/N) ";
cin >> repeat;
if (repeat == 'Y'){
(This is what i want to know)
}
cout<<"Thank you for using this program, goodbye!"<<endl;
return 0;
// Display the monthly charges
cout << fixed << showpoint << setprecision(2);
cout << "The converted amount is: " << conversion << endl;
cout <<""<<endl;
}
} while (choice != 3);
cout<<"Thank you for using this program, goodbye!"<<endl;
return 0;
}
Чтобы перезапустить цикл do-while, используйте continue. По логике, вы должны сначала распечатать историю, а затем сделать вопрос \ проверку.
В вашем
switchслучай3никогда не произойдет из-за условияifпередswitch.