#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
long input,negaAr[10],posiAr[10];
for (int x=0;x<10;x++)
{

cout<<"enter:";
cin>>input;
if (input<-1)
negaAr[x];
else if(input>=0)
posiAr[x];
}
cout<<"positive:"<<posiAr[x];
cout<<"negative:"<<negaAr[x];
getch();
}

i dont whats thee problem of this, ihave to input 10 integers and display the number of positive and negative.

Recommended Answers

All 14 Replies

i dont whats thee problem of this, ihave to input 10 integers and display the number of positive and negative.

You have no formatting making the program difficult to follow. See this.
See this too.

#include<conio.h>        // No longer a valid header file.  Very non-standard & non-portable.
#include<iostream.h>     // Years ago the .h version of this header was replaced. Use the current version without the .h
void main()              // main() has NEVER been a VOID.  It's INT!
{
clrscr();                // Worthless and annoying to the user.  Don't use it.
long input,negaAr[10],posiAr[10];
for (int x=0;x<10;x++)
{

cout<<"enter:";
cin>>input;
if (input<-1)
negaAr[x];               // What's this statement supposed to do? It does nothing.
else if(input>=0)
posiAr[x];               // Same with this one.
}
cout<<"positive:"<<posiAr[x];  // What's the value of X at this point? 
cout<<"negative:"<<negaAr[x];
getch();                 // Another non-standard and non-portable statement. Use CIN.
}

im using c++ 3.0 . without .h the library isnt working. so how can i get the number if its positive or negative?

negaAr[x]; // What's this statement supposed to do? It does nothing.

posiAr[x]; // Same with this one.

What WaltP wants to say is why have you taken an array here? Also you are not doing any computations on it. posiAr and negaAr should not be arrays bt simple integer variables and you need to increment them accordingly ( posiAr++ or negaAr++)

if i use posiAr++ it only count the number of postive. my problem here is how do i display all the positive and negative I input . i want to display what I inputted not to count.

i dont whats thee problem of this, ihave to input 10 integers and display the number of positive and negative.

This is what you said above.

Anyway, you have taken two arrays one for positive and one for negative numbers. Now , firstly you need to make an assignment to your array. Any positive number encountered should be assigned to the next element of posiAr and similarly for negative. Now the problem with this will be that if you use 'x' as your array index, you might get garbage values in your arrays.
Instead take two counter variables, say posCount and negCount ,initialize them to 0, increment them accordingly on encountering a number, and use that counter as your index in the respective array.

Also when you display your array, loop until you reach the respective count.

negaAr[x];               // What's this statement supposed to do? It does nothing.
}

Answer the question. Since this does nothing, we can't for sure tell you are trying to do with it.

where do i put the variables?

Answer the question. Since this does nothing, we can't for sure tell you are trying to do with it.

that is array where i save the postive inputted number.. and the negaAr is for the negative one. i want to display what is the positive and negative when i input 10 digits there.

Your if statement block will contain two things :
1. increment the respective variable
2. assign the number you have just read to the next element of that array (this will be done using the variable you just incremented. That will act as your array index)

There is a slight mistake in what i just wrote. Your will first do the assignment and then increment the counter (Since you counter will be initialized to zero)

for (int x=0;x<10;x++)
{

cout<<"enter:";
cin>>input;
if (input<-1)
nega++;
else if(input>=0)
posi++;
}
cout<<"positive:"<<posiAr[posi];
cout<<"negative:"<<negaAr[nega];
getch();
}

is this want you want to say? im only a beginner im so confused .

Ok you are on the right track but you still did not assign anything in the array. negaAr and posiAr contain nothing at this moment . whenever your input < 0, you need to put that input in negaAr and then do nega++.

Also,

if (input<-1)

you will miss -1 here. Either make it <= -1 or make it < 0

Commenting your code AND formatting it properly (second suggestion) helps a LOT!!!

for (int x=0;x<10;x++)
{

cout<<"enter:";
cin>>input;         // input a number
if (input<-1)       // if number is -2, -3, -4, and so on...
nega++;             // increment value to count it.
else if(input>=0)   // otherwise if 0, 1, 2, 3, and so on...
posi++;             // increment value to count it.

// what about -1?
// is 0 considered positive?
// The above comments are what's happening. Do they in fact explain what you want to happen?
}
cout<<"positive:"<<posiAr[posi];    // what is the value of posiAr[posi]?  I don't see anywhere 
                                    //where the posiAr[] array has any values in it at all.
cout<<"negative:"<<negaAr[nega];    // Same here.
getch();
}

Dude there is no need for an array to get the no. of positive and negative values. Make it something like

#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
long input,negaAr=0,posiAr=0;
for (int x=0;x<10;x++)
{
cout<<"enter:";
cin>>input;
if (input<-1)
negaAr++;
else if(input>=0)
posiAr++;
}
cout<<"positive:"<<posiAr;
cout<<"negative:"<<negaAr;
getch();
}
#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
long input,negaAr[10],posiAr[10];
for (int x=0;x<10;x++)
{

cout<<"enter:";
cin>>input;
if (input<-1)
negaAr[x];
else if(input>=0)
posiAr[x];
}
cout<<"positive:"<<posiAr[x];
cout<<"negative:"<<negaAr[x];
getch();
}

i dont whats thee problem of this, ihave to input 10 integers and display the number of positive and negative.

commented: Doesn't ANYBODY understand the concept of FORMATTING????? -4
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.