I'm trying to set up manipulators for Product description, Unit price, Quantity and Total but Unit price is not right under the shifted Product description. Also I get
Error C4700 uninitialized local variable 'price' and 'quantity'
You don't need the cout << right; and cout << setfill(' '); since those are the defaults. And even if you did need them, you would only need to do them once.
Also, you are trying to print price and quantity (with cout) before you even read them in (with cin). You need to read them in first.
If you want things to be farther to the right you either need to print some spaces (or possibly tabs) or make the setw value a lot bigger.
#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 << setw(5) << description;
cout << "Product description: ";
getline(cin, description);
cout << setfill(' ');
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;
}
#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 << setw(5) << description; // NOT NEEDED
cout << setw(21) << "Product description: ";
getline(cin, description);
cout << setfill(' ');
cout << setw(21) << "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 << setw(21) << "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;
}
Thanks for the help again...
I fixed now. It was depending on how many letters were being used within each setw. The longer the word; the longer the setting numbers for it. Here's how I fixed it with your help...
#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 << setw(26) << "Product description: ";
getline(cin, description);
cout << endl;
cout << setw(17) << "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 << setw(15) << "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 << setw(14) << "Total: $" << totalPrice << endl;
cin.get();
cin.get();
return 0;
}
Next question is...
Why am I not getting a decimal layout like on Line 50 for Line 33?
and
How can I cinch up the spaces between the output?
i.e.
Like the example between Lines 16 to 22.
#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 << setw(30) << "Product description: ";
getline(cin, description); //Prompt user enter a one word description
cout << endl;
cout << showpoint << setprecision(2);
cout << setw(31) << "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 << setw(31) << "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 << setw(31) << "Total: $" << totalPrice << endl;
cin.get();
cin.get();
return 0;
}