Issues with loop and setprecision

im having issues with this code. my problem is i need it to continue to run until i enter 0 as the "total". and i also need a setprecision to 1 decimal place on the answer.

thank you
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
  #include <iostream>

using namespace std;

double sum(double[],double);

int main () 
{
	int total;
	
	
	cout << "How many numbers would you like to enter? ";	
	cin >> total;
	
	while (total <= 0)
	
		cout << "Enter a number: ";
		cin >> total;
	}
	double num[total];
	
	for (int i = 0; i < total; i++) 
	{
		cout << "Enter number " << i + 1 << ":";
		cin >> num[i];
	}
	
	int sum = 0;
	int i = 0;
	
	while (i < total)
	{
		sum = sum + num[i];
		i++;
	}
	
	cout << "The average of the numbers you entered is " << sum/total << endl;

    return 0;
}
Topic archived. No new replies allowed.