445,655 Members | 1,005 Online
Need help? Post your question and get tips & solutions from a community of 445,655 IT Pros & Developers. It's quick & easy.

Help With Looping In C++

 P: 4 hey, im learning basic C++ courses and wanted some help with this problem. Plz help Thanks, Anand Q10 Message: Write a program that reads in ten whole numbers and that outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative or zero. T he user enters the ten numbers just once each and the user can enter them in any order. Your program should not ask the user to enter the positive numbers and the negative numbers separately. I have done this so far... Expand|Select|Wrap|Line Numbers int main() {      double sum_greater_than_zero = 24;      double sum_less_than_zero =0;     double sum_of_all = 0 ;     int number ;       cout << "Please press return after entering a value. \n ";     cout << "What number would you like to pick? \n ";     cin >> number;     cout << "Thank You ";       while ( number != 0 )     {                    sum_greater_than_zero *= number;           cout << "The sum is: " << sum_greater_than_zero++ << endl;     }                    if ( number > 0 )             sum_greater_than_zero += number;           else if ( number < 0 )              sum_less_than_zero += number;               return 0;   }   Plz help Anand Feb 25 '07 #1
7 Replies

 Expert 100+ P: 1,510 a couple of things which look wrong (see lines with << ) Expand|Select|Wrap|Line Numbers int main() {      double sum_greater_than_zero = 24;      double sum_less_than_zero =0;     double sum_of_all = 0 ;     int number ;       cout << "Please press return after entering a value. \n ";     cout << "What number would you like to pick? \n ";     cin >> number;     cout << "Thank You ";       while ( number != 0 )     {                    sum_greater_than_zero *= number;           cout << "The sum is: " << sum_greater_than_zero++ << endl;     }  <<  i think this is in the wrong place                    if ( number > 0 )             sum_greater_than_zero += number;           else if ( number < 0 )              sum_less_than_zero += number;   << read next number here   << put a } here             return 0;   } } Feb 25 '07 #2

 P: 4 it says illegal else without matching if... anand Feb 25 '07 #3

 P: 27 Expand|Select|Wrap|Line Numbers //Some code has been removed...this is not a functional program!   int main() {      cout << "Please press return after entering a value. \n ";     cout << "What number would you like to pick? \n ";     cin >> number;     cout << "Thank You ";       while ( number != 0 )     {            // operations...               cin>>number;       }       } This way, the program will terminate when the use enters zero value!! check ur while loop condition Feb 25 '07 #4

 P: 4 I tried it and the program works this way " it asks me to pick a number and then it just displays thank you." it doesn't perform any operations" Thanx Anand Feb 25 '07 #5

 Expert 2.5K+ P: 3,652 The program is waiting for another number. The code given above does not display a prompt inside the loop, so the loop will execute until a 0 is pressed. Feb 25 '07 #6

 P: 4 can someone jus make changes in the program ...u can read the question on top...plzzzz its eating my head! ANand Feb 25 '07 #7

 Expert 2.5K+ P: 3,652 No. You will have to write your own program - the experts at this site will not help you cheat. We are more than willing to help you, but we have given you quite enough help in this thread for you to solve the problem on your own - so do it. Feb 25 '07 #8