/*************************************************************
* 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>
usingnamespace 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.
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;
}
elseif (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 :)
#include <iostream>
usingnamespace 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;
}