i cannot figure out how to increase of items sold

Write a complete C++ program that asks for the price of an object and the amount of money given and then computes the amount of money to give back.

Make your program's input and output look exactly like this:

Enter price: 8.30
Enter amount received: 20.00
Your change is: 11.70
Part 1:

Add a while loop to your change program that repeats everything in the main function.
Exit the loop if the user types in a price of 0.

Part 2:

After the user has exited the loop, your program should print the following:
The number of items sold. Create a new variable called count and increase it by one each time something is sold.
The total price of the items sold. Create a new variable called total...
The average price of each item sold. Compute the average after the loop has exited.

This what is i have so far

int main()
{
double n1;
double n2;
double i = 0;

while(i <= n2)
{
cout << "Enter price: ";
cin >> n1;
cout <<endl;
{if( n1 == 0)
break;
}
cout << "Enter amount received: ";
cin >> n2;
cout <<endl;

double sum;
sum = n2 - n1;
cout << fixed << setprecision(2);
cout << "Your change is: " << (sum);
cout <<endl;
}


for(int count = n1; count <= n1; count++)
{cout << fixed << setprecision(2);
count++;
cout << "Items sold: " << count <<endl;

int total;
total = n1 * count;
cout << "Total price: " << total <<endl;

Please read this.
http://www.cplusplus.com/articles/z13hAqkS/

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
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	double n1;
	double n2;
	double i = 0;
	int count = 0;
	double total = 0;
	bool loop = true;

	while(loop)
	{
		cout << "Enter price: ";
		cin >> n1;
		cin.ignore();
		cout <<endl;
		total += n1;
		if( n1 == 0)
		{
			break;
		}
		
		cout << "Enter amount received: ";
		cin >> n2;
		cin.ignore();
		cout <<endl;

		double sum;
		sum = n2 - n1;
		cout << fixed << setprecision(2);
		cout << "Your change is: " << (sum);
		cout <<endl;
		count++;

	}/*end of while loop*/
	
		cout << fixed << setprecision(2);
		cout << "Items sold: " << count <<endl;
		cout << "Total price: " << total <<endl;
	
		
	cin.ignore();
	return 0;
	}
	
Thank appreciate it for the help it working now and thanks for the article
Topic archived. No new replies allowed.