Working w input

The program stops after quantity is entered?

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
  #include <iostream> 
#include <iomanip> 

using namespace 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;
}
Is it stopping, or is the window closing so fast that you can't read the output?

http://www.cplusplus.com/forum/beginner/1988/
It stops and closes out after quantity is input.
It's not calculating the totalPrice and outputting it.
Last edited on
Please read the thread I linked to.
Thanks
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.

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
#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 << "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;
}
I just started with C++ a few days ago; but I think I found one problem. (I didn't test for additional problems.)

Getline should be moved above; and replaced by cout...I'm pretty sure. :)

1
2
3
getline(cin, description);
cout << setfill(' ') << left << setw(25) << "Product description: "
<< right << " " << description << endl;
Last edited on
Thanks I'll give it a shot.
Nope. Didn't work.
Really. Before I got an error and it wouldn't run. Now I get:
1
2
3
4
5
6
7
8
9
EverythingForSale.com
Purchase receipt
Product description; test
Product description:      test
Unit price: 5

Quantity: 5

Total:  $25.00


Well, good luck anyway!
Thanks
Topic archived. No new replies allowed.