this is the program

#include <iostream>
using namespace std;
int main()

{
int digits;

cout<<"Enter 10 digits wether positive or negative: ";
cin>>digits;

//i dont know what to use so that i can separate positive and negative numbers and display it on screen..

//help me pls..,
}

Recommended Answers

All 8 Replies

You might want to investigate arrays..

const size_t ARRAY_SIZE = 10;
int MyIntArray[ARRAY_SIZE];

is it possible to separate negative and positive numbers when you use loops?

Separate how? Do you want them in two different arrays? Do you want to print them on two different lines? Do you want the negative numbers to sing and the positive numbers to dance? Be specific, or don't complain when nobody helps you.

This should help

if(num < 0){ /* the number is negative */ doStuffWithNegativeNumbers(); }
else{ /*The number is not negative */ doStuffWithNonNegativeNumbers(); }

heres the instruction:


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,
wether positive, negative or zero). The user enters the ten numbers just once each & the user can enter them in any order.
Your program should not ask the user to enter the positive numbers & negative numbers separately.

ex output:

-11 9 8 3 7 -65 -3 0 2 35

sum of positive #s:
sum of negative #s:
sum of all #s:

how can i make it?

If you don't want store that value then just use simple variable for getting input from user by using loop and and three other variable for storing sum

int number,total,total_positive,total_negative;
total=0;
total_positive=0;
total_negative=0;
cout<<"Enter 10 number:";
for(i=0;i<10;i++)
{
cin>>number;
if(number<0)
total_negative+=number;
else
total_positive+=number;
total+=number;
}

Best Of Luck.

commented: Read the rules and stop giving away homework. Guide to a solution, don't spoon feed. +0

If you don't want store that value then just use simple variable for getting input from user by using loop and and three other variable for storing sum

int number,total,total_positive,total_negative;
total=0;
total_positive=0;
total_negative=0;
cout<<"Enter 10 number:";
for(i=0;i<10;i++)
{
cin>>number;
if(number<0)
total_negative+=number;
else
total_positive+=number;
total+=number;
}

Best Of Luck.

I think Mr. Evan has warned you about this before. Read the rules and stop giving away homework. We guide students to solutions, we don't hand them a solution on a silver platter.
You really should work on your formatting too.

Heres the logic

You will need 2 variables
sumOfEven
sumOfOdd

//Inputting 
Loop 10 times
Prompt and read number
If ( number > 0 )
   add to sumOfEven numbers
Else
   add to sumOfOdd numbers
End if
End Loop

//Printing 
//This prints all numbers in a line
Loop 10 times
    Print all numbers in the array 
End loop

Print sumOfEven
Print sumOfOdd

Print sum of all #'s 
Loop 10 times 
    Print all numbers in the array
End loop

I know I gave too much away, but at least you still have to write the code

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.