Program help, average of postive and negative numbers

closed account (Diz60pDG)
I am writing a code and having some troubles with it, I got part of it down but I am not sure how to complete the rest. Below is the requirments

Write a program that reads in five whole numbers from the user. The program will calculate and output the following statistics about the five numbers:

● The sum of all of the positive numbers
● The sum of all of the non-positive numbers (less-than or equal to zero)
● The sum of all five numbers.
● The average of all of the positive numbers
● The average of all of the non-positive numbers (less than or equal to zero).
● The average of all five numbers.

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
using namespace std;

int main()
{

	int num1, num2, num3, num4, num5;
	int positive, negative;


	cout << "Please enter 5 whole numbers: " << endl;
	cin >> num1;
	cin >> num2;
	cin >> num3;
	cin >> num4;
	cin >> num5; 

	if (num1 > 0)
	{
		num1 = positive;
	}
	else
	{
		num1 = negative;
	}

	if (num2 > 0)
	{
		num2 = positive;
	}
	else
	{
		num2 = negative;
	}

	if (num3 > 0)
	{
		num3 = positive;
	}
	else
	{
		num3 = negative;
	}

	if (num4 > 0)
	{
		num4 = positive;
	}
	else
	{
		num4 = negative;
	}

	if (num5 > 0)
	{
		num5 = positive;
	}
	else
	{
		num5 = negative;
	}


	int sum;
	sum = (num1 + num2 + num3 + num4 + num5);
	int average;
	average = (num1 + num2 + num3 + num4 + num5) / (5);
	

	
	cout << "The sum of all five numbers is " << sum << "." << endl;
	

	cout << "The sum of all the "  "positive numnbers is " << endl;


	cout << "The sum of the " "negative numbers is " << endl;


	cout << "The average of all five numbers is " << average << "." << endl;


	cout << "The avergae of the " "positive numbers is " << endl;


	cout << "The average of the " "negative numbers is " << endl;


	



	return 0;
}



Thank you for any 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
#include <iostream>
using namespace std;

int main() {
	
int ps=0, pc=0, ns=0, nc=0, ts=0, tc= 0;
double pa, na, ta;
int n[5] ={0};

for (int &x: n)
	{
	cout << "enter number:\n";
	cin >> x;
	if(x>0)
		{
		 ps+=x;
		 pc++;
		}
	else
		{
		 ns+=x;
		 nc++;
		}
	}

if(pc)
	pa = (double)ps/pc;
	
if(nc)	
	na = (double)ns/nc;
		

 ts = ps+ns;
 ta = (double)ts/5;
 
 cout << "ps ns ts : " << ps << " " << ns  << " " << ts <<endl;
 cout << "pa na ta : " << pa << " " << na  << " " << ta <<endl; 
   
return 0;
}
Topic archived. No new replies allowed.