Average numbers

im stump right now. im looking in my book and i cant solve this program to do what is required this is what i have so far.
"these are the requirements for the assignment. we havent gotten to arrays yet so if you can help with the most basic solution

Design and code a program that asks the user how many numbers from which to determine an average.
Then prompt the user for the integer values and sum them to a total.
Display the sum of the numbers and the calculated average with appropriate accompanying text.
The average should be shown with 1 decimal place.
Repeat the process until the user enters zero (0) as the number of values to be averaged.
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
  // algorithm

// 1) Ask user to enter amount of number they wish to average
//  a if user enters a number greater than zero 
//     1) enter the numbers to avgerage
//     2) calculate average to 1 decimal point
//     3) loop back to start
//  b) if user enters zero 
// 2)  end program

#include <iostream>
#include <cmath>
#include <iomanip>

  using namespace std;
  
  double sum(double[],double);
  
  int main()
  {
  	int num, num2;
    double total;
    
    
   
   do
   { 
      cout << "Enter the amount of numbers to average: " ;
      cin >> num;
      
      if ( num > 0 )
      {
      	
      	
		  for ( int i = 0; i < num; i++)
      	{  
      	    cout << "Enter number " << i + 1 << ":";
      	    cin >> num2;
      	    
      	}
      	    
    int sum=0;
	int i=0;
	
	while (i < total)
	{
		sum = sum + num2;
		i++;
	}
	
	cout << "The average of the numbers you entered is " << sum/total << endl;
      	    
      	    
	  }
   	 
   system("pause");
   return 0;
   } while (num > 0);
  }
  
  
1
2
3
4
5
6
 for ( int i = 0; i < num; i++)
 {  
      cout << "Enter number " << i + 1 << ":";
      cin >> num2;
      	    
  }


You're on the right track but you're missing a key point. You enter a number in num2, but then you dont do anything with it. Here is where your "total" is suppose to come in handy, which you never use in your code by the way.

total = tatal + num2;

This will sum up all your numbers entered and put them into total.

After that you just have to divide it by the variable that holds your amount of numbers, which in this case is num.
so i adjusted a few things around so i can get it to loop correctly now that it can solve an equation.
but what happing now it not doing the math correctly when i enter 1,2,3,4,5 it comes out with the answer is 5 which should be 3
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
// algorithm

// 1) Ask user to enter amount of number they wish to average
//  a if user enters a number greater than zero 
//     1) enter the numbers to avgerage
//     2) calculate average to 1 decimal point
//     3) loop back to start
//  b) if user enters zero 
// 2)  end program

#include <iostream>
#include <cmath>
#include <iomanip>

  using namespace std;
  
  double sum(double[],double);
  
  int main()
  {
  	int num, num2;
    double total;
    
    
   
   do
   { 
      cout << "Enter the amount of numbers to average: " ;
      cin >> num;
      
      if ( num > 0 )
      {
      	
      	
		  for ( int i = 0; i < num; i++)
      	{  
      	    cout << "Enter number " << i + 1 << ":";
      	    cin >> num2;
      	    total = total + num2;
      	}
      	    
    int sum=0;
	int i=0;
	
	while (i < total)
	{
		sum = sum + num2;
		i++;
	}
	
	cout << "The average of the numbers you entered is " << sum/total << endl;
      	    
      	    
	  }
   	 
   
   } while (num > 0);
   system("pause");
   return 0;
  }
i see what its doing its not adding up all the numbers its taking the last value entered and using that as the answer how would i go about fixing it to actually take the sum of all number input and get a average
It is adding all the numbers together. That is what total = total + num2; is doing

1
2
3
4
5
6
7
8
 int sum=0;
	int i=0;
	
	while (i < total)
	{
		sum = sum + num2;
		i++;
	}


I have no idea what this code is doing here.

You have the total, or the sum if you want to call it that. Its in the variable total. What else is missing for the average? The amount of numbers entered. And you already have that.

1
2
 cout << "Enter the amount of numbers to average: " ;
      cin >> num;


So what's left is doing average = total/num; no?
so thank you again now everything is running good.
the one last thing i had to add was setpresision to the answer

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
// algorithm

// 1) Ask user to enter amount of number they wish to average
//  a if user enters a number greater than zero 
//     1) enter the numbers to avgerage
//     2) calculate average to 1 decimal point
//     3) loop back to start
//  b) if user enters zero 
// 2)  end program

#include <iostream>
#include <cmath>
#include <iomanip>

  using namespace std;
  
  
  
  int main()
  {
  	int num, num2;
    int total; 
	float avg;
    
    
    
   
   do
   { 
      cout << "Enter the amount of numbers to average: " ;
      cin >> num;
      
      if ( num > 0 )
      {
      	
      	
		  for ( int i = 0; i < num; i++)
      	{  
      	    cout << "Enter number " << i + 1 << ":";
      	    cin >> num2;
      	    total = total + num2;
            avg = total/num;
	  	}
      	
      	    cout << "The average of the numbers you entered is " << setprecision(2) << avg << endl;
      	    
      	    
	  }
   	 
   
   } while (num > 0);
   system("pause");
   return 0;
  }
  

when i do this its not calculating the answer correctly.
i tried changing the avg to a double. i tried throwing a showpoint in there with setprecision. i all out of idea i know about.
bump
Make everything a float and it should work. I could be wrong, though. You need the total, num and num2 to all be floats (or doubles -- but not ints).
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
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	int num, num2;

	do {
		cout << "Enter the amount of numbers to average: ";
		cin >> num;
		int sum = 0;
		if (num > 0) {

			for (int i = 0; i < num; i++) {
				cout << "Enter number " << i + 1 << ":";
				cin >> num2;
				sum = sum + num2;
				cout << "sum:" << sum;
			}
			cout << "The average of the numbers you entered is "
					<< (sum / num) << endl;
		}
	} while (num > 0);

	return 0;
}

Enter the amount of numbers to average: 2
Enter number 1:12
sum:12Enter number 2:12
sum:24The average of the numbers you entered is 12
Topic archived. No new replies allowed.