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!
#include<iostream>
usingnamespace 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.
elseif( (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;
}
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)