c++ - 我将如何允许用户再次使用程序?
问题描述
对 C++ 很陌生,如果我没有使用正确的术语,对不起!我制作了一个程序,允许用户在输入总账单后计算小费金额。我希望程序询问他们是否要检查另一个金额,如果他们不这样做,那么它将关闭。
这是我目前拥有的
#include <iostream>
using namespace std;
int main()
{
double bill, ten, fifteen, twenty, end, end2, end3;
cout << "Enter your bill's total: ";
cin >> bill;
ten = 0.1;
fifteen = 0.15;
twenty = 0.2;
end = ten * bill;
end2 = fifteen * bill;
end3 = twenty * bill;
cout << "10%: " << end << endl;
cout << "15%: " << end2 << endl;
cout << "20%: " << end3 << endl;
system("pause");
return 0;
}
解决方案
如果你想要一个操作是 preform *直到你应该使用循环
#include <iostream>
using namespace std;
int main()
{
double bill, ten, fifteen, twenty, end, end2, end3;
bool done = false;
while(!done){
cout << "Enter your bill's total: ";
cin >> bill;
ten = 0.1;
fifteen = 0.15;
twenty = 0.2;
end = ten * bill;
end2 = fifteen * bill;
end3 = twenty * bill;
cout << "10%: " << end << endl;
cout << "15%: " << end2 << endl;
cout << "20%: " << end3 << endl;
cout << "again? y/n";
char res;
cin >> res;
if(res == 'n')
done=true;
}
system("pause");
return 0;
}
推荐阅读
- opencv - CMake、.dll vs .dll.a vs .a:我应该在 CMake 配置中指定什么库?
- .net - AccessViolationException 以外的损坏状态异常类型
- java - 如何在画布上以原始格式绘制更多矩形?
- javascript - 使用 Enzyme 和 Sinon 进行内部调用单元测试
- c# - 如何在 Windows 应用程序打包项目中处理 URI 激活?
- flutter - 在 SafeArea 中获取小部件高度的正确方法
- python - 如何将 T-1 日期值打印到 Excel 表
- angular - 在 angular.json 中自动添加脚本和样式
- javascript - 如何在粘性容器内创建类似苹果的滚动效果?
- electron - 传递请求结果以查看