counting inputs in an array

Hi, Im a beginner of c++, I'm trying to get 5 integers from user inputs
and i want them to be printed out on a single line. Then i want to count the number of odd integers in the loop, stop and exist the loop if the number is negative, and last print the odd numbers.
For example, if the inputs are 4 2 1 -1 5
the count would be 3
I dont get it why the code is not working, could anyone please guide me thro. this, I'll be very appreciated, thanks alot for your time!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<iostream>
using namespace std;
int main(){

int num[5];
cout<<"Enter integers: ";

//get user inputs
for(int c=0; c<5; c++){
cin>>num[c];
}

//print out in single line
for(int i=0; i<5; i++){
	cout<<num[i]<<", ";
}
cout<<endl;

//count odd elements
int count=0; 
while(count<=5){
	if (num [i] <0){
		break;	//exit the loop if it is neagative number.
	else if( (num[i] != 0) || (num[i]%2 != 2) )
		count ++;
	}
}
cout<<"the count is: "<<count<<endl;
cout<<num[i];	//print the number of odd values


return 0;
}


Last edited on
1
2
3
4
5
6
7
8

while(count<=5){
	if (num [count] <0){
		break;	//exit the loop if it is neagative number.
	else if( (num[count] != 0) || (num[count]%2 != 2) )
		count ++;
	}
}
also curly brackets on line 22 and 26 is not needed there.
thanks alot for your quick helps, i tried to compile it but there's error, i dont understand what are these, could you please help me take a look

may14.cpp: In function âint main()â:
may14.cpp:28:11: error: name lookup of âiâ changed for ISO âforâ scoping [-fpermissive]
cout<<num[i]; //print the number of odd values
^
may14.cpp:28:11: note: (if you use â-fpermissiveâ G++ will accept your code)
Topic archived. No new replies allowed.