Write a C++ program according to the following algorithm: Declare a string varia
ID: 3586701 • Letter: W
Question
Write a C++ program according to the following algorithm: Declare a string variable productName Declare integer variable productQuantity Declare real number variables productUnitPrice, productTotalPrice Display welcome message to the user- "Welcome to the Inventory Calculation Program Ask the user to enter the product name - "Please enter the product name" Store name entered into productName Ask the user to enter the quantity of the product - "Please enter product quantity" Store integer entered into productQuantity Ask the user to enter the unit price of the product - "Please enter product unit price" Store real number entered into productUnitPrice Calculate productTotalPrice -productQuantity multiplied by productUnitPrice Display result to the user in the following format: Come u Product Quantity Pen,otal p thvee o va iat fil Unit Price (S) 1.05 100 The total price is: S 105.00 Create THREE additional variations of the output using the include iomanip> operations. Display thank you message to user - "THANK YOU for using the program written by [your name]"Explanation / Answer
#include<iostream>
#include<iomanip>//including iomanip for output operations
#include<string>
using namespace std;
int main()
{//variable declaration
string productName = "";
int productQuantity;
double productUnitPrice;
double productTotalPrice;
//prompting and reading input...
cout<<"welcome to the Inventory Calculation program "<<endl;
cout<<"Please enter product name:";
cin>>productName;
cout<<"Please enter product quantity:";
cin>>productQuantity;
cout<<"Please enter product unit price:";
cin>>productUnitPrice;
//calculating total price
productTotalPrice = productUnitPrice*productQuantity;
cout<<productTotalPrice<<endl;
//printing output...using iomanip functions..
cout<<"Product"<<setw(10)<<"Quantity"<<setw(10)<<"Unit Price($) ";//setw(n)...produces n spaces//
cout<<productName<<setw(13)<<productQuantity<<setw(12)<<productUnitPrice<<endl;
cout<<"The total price is:$"<<setprecision(3)<<productTotalPrice<<endl;//setprecision(n)...only n digits are printed after decimal point
return 0;
}
output:
welcome to the Inventory Calculation program
Please enter product name:pen
Please enter product quantity:100
Please enter product unit price:1.05
105
Product QuantityUnit Price($)
pen 100 1.05
The total price is:$105
Process exited normally.
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.