473,471 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help With Looping In C++

4 New Member
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
  1. int main()
  2.     double sum_greater_than_zero = 24; 
  3.     double sum_less_than_zero =0;
  4.     double sum_of_all = 0 ;
  5.     int number ;
  6.  
  7.     cout << "Please press return after entering a value. \n ";
  8.     cout << "What number would you like to pick? \n ";
  9.     cin >> number;
  10.     cout << "Thank You ";
  11.  
  12.     while ( number != 0 )
  13.     {
  14.                    sum_greater_than_zero *= number;    
  15.       cout << "The sum is: " << sum_greater_than_zero++ << endl;
  16.     }
  17.                    if ( number > 0 )
  18.             sum_greater_than_zero += number;
  19.  
  20.         else if ( number < 0 )
  21.              sum_less_than_zero += number;
  22.  
  23.  
  24.  
  25.         return 0;
  26.   }
  27.  
Plz help
Anand
Feb 25 '07 #1
7 3243
horace1
1,510 Recognized Expert Top Contributor
a couple of things which look wrong (see lines with << )
Expand|Select|Wrap|Line Numbers
  1. int main()
  2.     double sum_greater_than_zero = 24; 
  3.     double sum_less_than_zero =0;
  4.     double sum_of_all = 0 ;
  5.     int number ;
  6.  
  7.     cout << "Please press return after entering a value. \n ";
  8.     cout << "What number would you like to pick? \n ";
  9.     cin >> number;
  10.     cout << "Thank You ";
  11.  
  12.     while ( number != 0 )
  13.     {
  14.                    sum_greater_than_zero *= number;    
  15.       cout << "The sum is: " << sum_greater_than_zero++ << endl;
  16.     }  <<  i think this is in the wrong place
  17.                    if ( number > 0 )
  18.             sum_greater_than_zero += number;
  19.  
  20.         else if ( number < 0 )
  21.              sum_less_than_zero += number;
  22.  
  23. << read next number here 
  24.  << put a } here
  25.  
  26.  
  27.         return 0;
  28.   }
  29. }
Feb 25 '07 #2
Anand Churi
4 New Member
it says illegal else without matching if...
anand
Feb 25 '07 #3
bravephantom
27 New Member
Expand|Select|Wrap|Line Numbers
  1. //Some code has been removed...this is not a functional program!
  2.  
  3. int main()
  4.     cout << "Please press return after entering a value. \n ";
  5.     cout << "What number would you like to pick? \n ";
  6.     cin >> number;
  7.     cout << "Thank You ";
  8.  
  9.     while ( number != 0 )
  10.     {
  11.            // operations...
  12.               cin>>number;
  13.  
  14.     }  
  15.  
  16.   }
This way, the program will terminate when the use enters zero value!!
check ur while loop condition
Feb 25 '07 #4
Anand Churi
4 New Member
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
Ganon11
3,652 Recognized Expert Specialist
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
Anand Churi
4 New Member
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
Ganon11
3,652 Recognized Expert Specialist
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

Sign in to post your reply or Sign up for a free account.

Similar topics

31
by: da Vinci | last post by:
OK, this has got to be a simple one and yet I cannot find the answer in my textbook. How can I get a simple pause after an output line, that simply waits for any key to be pressed to move on? ...
3
by: frozenee | last post by:
I've noticed that the listings in help don't take you to correct topic. anyone else have this problem? Is there a fix?
4
by: Paul M | last post by:
Larry, i've got an xml file which has multiple cities as the top level item. When i read it in using XMLReader, and define the variables, as below, it finds the correct number of cities in the...
2
by: atreide_son | last post by:
hello all... yes i'm a newbie and i need help. i have an assignment due for class, but I don't know i'm stuck and can't get out from under myself. here's the focus of the program: Write...
4
by: Jeffrey Barrett | last post by:
Can someone tell me why I'm having this problem: When I select drink 5 and deposit too little money, there's a problem with the 'difference' variable. Try to deposit $.80 instead of the full $.85...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
21
by: asif929 | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
1
by: darrel | last post by:
Hi vb master i need help on this here my code: If Combo1(0) = rs.Fields("TimeStart") And Combo4(0) = rs.Fields("TimeEnd") And Combo2(0) = rs.Fields("ROOM") And Combo3(0) = rs.Fields("DAYS")...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.