我将如何允许用户再次使用程序?

时间:2018-09-09 06:55:57

标签: 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;
}

1 个答案:

答案 0 :(得分:0)

如果您希望执行某项操作*直到某些事情发生,您应该使用循环

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