-5

Pretty new to C++, sorry if I am not using the correct terms! I made a program where it allows the user to calculate the amount to tip after inputting the total bill. I would like the program to ask if they want to check another amount and if they don't, then it will close.

Here is what I currently have

#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;
}
aospade
  • 3
  • 2
  • 2
    How about using a loop? – Uwe Keim Sep 09 '18 at 06:56
  • ahh now I know what is called, I kept searching for "repeat program", lol im stupid – aospade Sep 09 '18 at 07:24
  • @aospade If youare serious about learning C++ it's better to find a [good book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) you can read instead of learning by google searches. – john Sep 09 '18 at 08:41

1 Answers1

0

If you want an operation to be preform *untill something you should use a loop

#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;
    }
Dr.Haimovitz
  • 1,568
  • 12
  • 16