Académique Documents
Professionnel Documents
Culture Documents
Code:
#include <iostream>
using namespace std;
int main()
{
int gallonsOfGas, numberOfMilesPerTank, MPG;
cout << "How much gallons of gas can your car hold?\n";
cin >> gallonsOfGas;
cout << "How many miles can your car drive on a fulltank?\n";
cin >> numberOfMilesPerTank;
MPG = numberOfMilesPerTank / gallonsOfGas;
cout << "Your MPG is " << MPG << " Miles Per Gallon" <<
endl;
system("pause");
return 0;
}
2. Stadium Seating
There are three seating categories at a stadium. For a softball game, Class A seats
cost $15, Class B seats cost $12, and Class C seats cost $9. Write a program that
asks how many tickets for each class of seats were sold, then displays the amount
of income generated from ticket sales. Format your dollar amount in a xed-point
notation with two decimal points and make sure the decimal point is always
displayed.
Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double ClassA, ClassB, ClassC, totalIncome;
cout << "How many Class A tickets were sold?\n";
cin >> ClassA;
cout << "How many Class B tickets were sold?\n";
cin >> ClassB;
cout << "How many Class C tickets were sold?\n";
cin >> ClassC;
cout << xed;
cout << setprecision(2);
totalIncome = ClassA * 15 + ClassB * 12 + ClassC * 9;
cout << "Total Income Generated: $" << totalIncome <<
endl;
system("pause");
return 0;
}
3. Housing Costs
Write a program that asks the user to enter their monthly costs for each of the
following housing related expenses:
The program should then display the total monthly cost of these expenses, and the
total annual cost of these expenses.
Code:
Code: