93.4k views
4 votes
Write a program that asks for the number of units sold and computes the total cost of the purchase. Input validation: Make sure the number of units is greater than 0. Use output (stream) manipulators: 2 digits after the decimal point g

User Benjguin
by
4.6k points

1 Answer

5 votes

Answer:

Step-by-step explanation:

The following code is written in C++, it asks the user for input on number of units sold and places it in a variable called units_sold. Then it asks for the package price and places that value in a variable called package_price. Finally it multiplies both values together into a variable called final_price and adjusts the decimals.

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

// Variables

int units_sold,

final_price;

// ask user for number of units sold

cout << "\\Enter number of units sold: ";

cin >> units_sold;

//ask for Package price

cout << "\\Enter Package Price: ";

cin >> package_price;

// Total amount before discount

final_price = units_sold * package_price;

cout << setprecision(2) << fixed;

cout << endl;

return 0;

}

User Chris Snell
by
5.9k points