#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
float price; // price of each item
int quantity; // number of items purchased
float totalPrice; // total price of all items purchased
cout << "Enter the price of an item: ";
cin >> price;
cout << endl;
// Write an input statement to read value entered by user and store it in variable price.
// Prompt user to enter the quantity.
// Write statement to read input for the quantity
cout << "Enter the quantity: ";
cin >> quantity;
cout << endl;
// Write a statement to calculate the total price and assign it to totalPrice.
// Write an output statement to display the output with proper label e.g,
// Total Price is: $1762.34
totalPrice = price * quantity;
cout << setfill (' ') << left << setw (20) << "Total Price is: "
<< setfill (' ') << right << " $"
<< setw (8) << totalPrice << endl;
return 0;
}
Now I'm trying to set the parameters for Product description 9 characters to the right under Purchase receipt. I'm trying to use setfill with getline. I need a little help with this one.
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
int main()
{
string description;
float price; // price of each item
int quantity; // number of items purchased
float totalPrice; // total price of all items purchased
cout << fixed << showpoint << setprecision(2); //sets the output for decimal
//Needs to look like this... as an example...
//EverythingForSale.com
//Purchase receipt
// Product description: Iphone6
// Unit Price: $560.99
// Quantity: 2
// Total: $1121.98
cout << "EverythingForSale.com" << endl;
cout << "Purchase receipt" << endl;
cout << "Product description; ";
getline(cin, description) << setfill(' ') << left << setw(25) << "Product description: "
<< right << " " << description << endl;
cout << "Unit price: ";
cin >> price;
cout << endl;
// Write an input statement to read value entered by user and store it in variable price.
// Prompt user to enter the quantity.
// Write statement to read input for the quantity
cout << "Quantity: ";
cin >> quantity;
cout << endl;
// Write a statement to calculate the total priceright and assign it to totalPrice.
totalPrice = price * quantity;
// Write an output statement to display the output with proper label e.g,
// Total Price is: $1762.34
cout << "Total: $" << totalPrice << endl;
cin.get();
cin.get();
return 0;
}