lesser-equity

Magazine
Go Back   Computer Juice > Computer Software > General Software Chat

Register


 Default 

Urgent C++ Help!




Reply
 
Thread Tools
  #1  
Old 24th Sep 2008, 17:13
Member Group
 
Default Urgent C++ Help!

I asked about this the other day. I desperately need some help with this problem.
--------------------------------------------------------------------------------
Write a program that reads in ten whole numbers and that ouputs 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. The 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.


One person responded and here's the code he gave me.
----------------------------------------------------------------------------------
Declare an int for the input number:


Code:
int candidate;
...then create a for loop to ask for input 10 times:


Code:
for (int i=0; i<10; i++){// stuff goes here}
and then cin >> to your int:


Code:
cin >> candidate;
Then you can check whether each number is less than or equal to zero. Then add it to a running total you've already declared as an int. So it'll look somewhat like this:

Code:
int candidate;int posTotal = 0;int negTotal = 0;int allTotal = 0;for (int i = 0; i < 10; i++){cin >> candidate;if (candidate < 0} posTotal = posTotal + candidate;else negTotal = negTotal + candidate;}
Then you can just add up the two totals at the end:


Code:
allTotal = posTotal + negTotal;
And you'll have all three totals, which you can then output any way you like.

--------------------------------------------------------------
The code he gave me didn't work, it only read the first number I entered in. I really need to get this done since it's due tommorow so please help.
  #2  
Old 24th Sep 2008, 17:47
Member Group
 
Default Urgent C++ Help!

Never mind, I figured it out. Feel free to delete this thread.
  #3  
Old 24th Sep 2008, 18:32
Donor Group
 
Default Urgent C++ Help!

Next time reply to your own thread rather than making a new one so I can actually see it.
__________________
"I loved the P182 so much that, when my wife's system was all noisy and needed all sorts of cleaning, I bought her one. Then, when I wanted a cat, I bought a P182. The P182 is not a cat per se, but it's still an excellent buy."
__________________

My System: 日夏子

Processor(s):
Core 2 Duo E6400 2.13 -> 3.01ghz
Motherboard:
MSI P6N SLI Platinum LGA 775
RAM Memory:
2GB Patriot Extreme Performance
Graphics Card(s):
PNY 8800GTS 320MB
Sound Card:
Sound Blaster Xtremegamer 7.1
Hard Drive(s):
80GB + 500GB
Optical Drive(s):
2x SATA
Case / PSU:
Antec 900 + 620W Aerocool zeroDBA
Cooling:
4x 120mm Yate-Loon + 200mm top
Network / Internet:
Qwest
Monitor(s):
Dell 22" S2209W (1920x1080)
Operating System(s):
Windows XP + 7
Reply

Register

Bookmarks

Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent help CC xactly General Hardware Chat 1 28th May 2008 06:40
Urgent - please help! teenee23 Laptops, Mobiles & PDAs 1 18th May 2008 15:49
URGENT Help Please! teenee23 Windows Operating Systems 8 3rd Apr 2008 03:56
Urgent, please help alih786 General Hardware Chat 4 30th Jan 2008 13:46
Urgent Help Required Please :) kelvin Graphics Cards & Monitors 7 30th Dec 2007 12:13
Thread Tools




Arabic Bulgarian Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Finnish French German Greek Hebrew Hungarian Italian Japanese Korean Latvian Lithuanian Norwegian Polish Portuguese Romanian Russian Serbian Slovak Spanish Swedish Thai Turkish Ukrainian

Copyright ©2006 - 2009 Computer Juice.

Powered by vBulletin® Copyright ©2000 - 2009 Jelsoft Enterprises Ltd. SEO by vBSEO ©2009, Crawlability, Inc.