Don't Know How to finish This Code..

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
/************************************************************* 
 * Description: Reads in 10 integers and prints out	         *
 * - the sum of all the positive numbers                     *
 * - the sum of all the negative numbers                     *
 * - the sum of ALL numbers	                                 *
 *************************************************************/

#include <iostream>

using namespace std;

int main()
{
	
	int MyNumber, AllSum, GreaterSum, LessSum, i;
	
	cout << "This program produces the sum of 10 numbers as entered by the user " 
	<< endl << "and also reports the sum of the positive numbers " 
	<< endl << "and the sum of the negative numbers entered. " << endl;
	
	// Initialize the variables 
	AllSum = 0; 
	GreaterSum = 0; 
	LessSum = 0;
	i = 1;
	
	// Begin the loop
	do {
		
		// Get input from user
		cout << "Enter a number "; 
		cin >> MyNumber;
		                               // update each summation as needed
		Update AllSum here
		
		Update GreaterSum
			As Needed
		Update LessSum
			As Needed
		
		i++;         //update the loop control variable
	
	} while (i != XX);
	
	cout << "Sum of the number greater than zero = " << GreaterSum << endl; 
	cout << "Sum of the numbers less tha zero = " << LessSum << endl;
	cout << "Total sum = " << AllSum << endl;
	
	return 0;
	
}


What should I put at line 34 through 39 and also line 43. Please help me out.

Thanks in advance.
Try putting cin into a while not sure if it will work, im new:)

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
int count;
while (cin >> MyNumber)
{
   
    for(int i=0; i <10; i ++) // loops through for how many numbers you add
    {
     ++count; 
     if(count <10)
    {
      cerr<<"Not enough integers specified"<<endl;
      cerr<<"Giving up..."<<endl;
      break;
    }
    else if (count == 10)
      ... // your code to find the sum of all
    }
    if(MyNumber >=0)
    {
      ...  // sum of all positive numbers
    }
    if(MyNumber <0)
    {
     ... // sum of negative numbers
    }
}         


not 100% sure this will work since I myself am in my first semester of c++ but if I were presented this problem this would be my first idea, tell me how or if it works or if im wrong :)

Last edited on
closed account (zb0S216C)
You could try this:

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

using namespace std;

int main()
{
	
	int MyNumber, AllSum, GreaterSum, LessSum, i;
	
	cout << "This program produces the sum of 10 numbers as entered by the user " 
	<< endl << "and also reports the sum of the positive numbers " 
	<< endl << "and the sum of the negative numbers entered. " << endl;
	
	// Initialize the variables 
	AllSum = 0; 
	GreaterSum = 0; 
	LessSum = 0;
	i = 1;
	
	// Begin the loop
	for( AllSum = 0; AllSum < 10; AllSum++ )
        {
             cin >> MyNumber;

             if( ( ( MyNumber >= 0 ) ? true : false ) == true )
             {
                     // Update GreaterSum...
             }
             else
                     // Update LessSum...
        }
	
	cout << "Sum of the number greater than zero = " << GreaterSum << endl; 
	cout << "Sum of the numbers less tha zero = " << LessSum << endl;
	cout << "Total sum = " << AllSum << endl;
	
	return 0;
	
}
Last edited on
Topic archived. No new replies allowed.