DISPLAY POSITIVE AND NEGATIVE

#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();
}

it accept`s 10 integer but my problem is the output. i have to preview the inputed positive and negative numbers.
"Preview"? What does that mean?
no i mean display the positive and negative..
Is your code compliable? You may want to browse
http://www.cplusplus.com/doc/tutorial/arrays/
How do you take input?
This code... Makes me cringe
You've got several errors there, bouldermash. :(

1. Although some compilers still support <iostream.h>, it's old and should not be used. Nowadays it's <iostream>.
2. Again, although some compilers still support it, void main() isn't correct C++. int main(), however, is!
3. I see no std:: prefixes or using namespace std;
4. Although this isn't technically an error, please avoid using <conio.h>. It varies way too much between compilers to be safe...

-Albatross
Here is an explanation of the things wrong in your array:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<conio.h>
#include<iostream> //not iostream.h
using namespace std; // required for cout, cin

void main()
{
	//clrscr(); not in conio.h, just get rid of this.
	long input,Ar[10]; // just use 1 array
	for (int x=0;x<10;x++)
	{
		cout<<"enter:";
		cin>>input;
		Ar[x] = input; // You need to assign a value
	}

	for (int x=0; x<10; x++) // You need to loop to read each value in an array seperately
	{
		cout << ( Ar[x]<0? "negative:" : "positive: ") << Ar[x] << endl; 
		//Displays negative or positive, then outputs the value
		//Don't forget to end the line or things will look a little messy.
	}
	getch();
}
Last edited on
simply put, you've done it all wrong .
Topic archived. No new replies allowed.