Left and right manipulators

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'

How do you set it up?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  #include <iostream> 
#include <iomanip> 
#include <string>

using namespace 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 << right;
	cout << setfill(' ');
	cout << setw(5) << description;
	cout << "Product description: ";
	getline(cin, description);
		
	cout << right;
	cout << setfill(' ');
	cout << setw(5) << price;
	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 << right;
	cout << setfill(' ');
	cout << setw(5) << quantity;
	cout << "Quantity: ";
	cout << left;
	cout << setfill(' ');
	cout << setw(5) << 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;
}
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.
Ok now I have the Product description in the right spot.
How do I get Unit price, Quantity and Total following right under/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream> 
#include <iomanip> 
#include <string>

using namespace 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;
}
I didn't correct the other issues tpb mentioned; I just fixed the alignment. (If you want 'them' more to the right...just increase the setw() value.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream> 
#include <iomanip> 
#include <string>

using namespace 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;
}
Last edited on
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...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream> 
#include <iomanip> 
#include <string>

using namespace 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;
}
Last edited on
Cool!
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream> 
#include <iomanip> 
#include <string>

using namespace 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;
}
Topic archived. No new replies allowed.