首页 > 解决方案 > 我将如何允许用户再次使用程序?

问题描述

对 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;
}

标签: c++

解决方案


如果你想要一个操作是 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;
    }

推荐阅读