How to close the program after the user enters a character and presses the
enter key?
I just started learning C++ programming. My program runs perfectly but i
also need it to close when the user enter s a character and presses the
enter key. I have no idea how that is supposed to be done. any help will
be really appreciated. My code so far is(runs fine) :
#include <iostream>
using namespace std;
int main()
{
int money_spent, money_tendered;
cout << "Enter the total amount spent: \n";
cin >> money_spent;
cout << "Enter the amount tendered: \n";
cin >> money_tendered;
int balance = money_tendered - money_spent;
int ten_bills = balance / 1000;
balance = balance % 1000;
int five_bills = balance / 500;
balance = balance % 500;
int dollar_coins = balance / 100;
balance = balance % 100;
int quater_coins = balance / 25;
balance = balance % 25;
int dimes = balance / 10;
balance = balance % 10;
int nickels = balance / 5;
balance = balance % 5;
int pennies = balance;
cout << " \n \n"
<< "Your change is: \n"
<< ten_bills << " tenn dollar bill(s). \n"
<< five_bills << " five dollar bill(s). \n"
<< dollar_coins << " one dollar coin(s). \n"
<< quater_coins << " quater(s). \n"
<< dimes << " dime(s). \n"
<< nickels << " nickel(s). \n"
<< pennies << " pennie(s). \n";
return 0;
}
No comments:
Post a Comment