0
Array c++
hello whats the problem in this code i get a wrong output:( #include <iostream> using namespace std; int main() { int array[10], b=0 , N=10; for (int i=0; i<N; i++){ if (b<=10){ cin>>array[i]; b++; } cout<<"the integers that less than or equal 10 is:"<<b<<endl; return 0; } }
2 Answers
+ 1
read the inputs into an array in a for loop.
then use a 2nd for loop to cycle through the array again and print only if the current element is lesser or equals to N. or put this into the first loop but only after the reading.
the if(b<10) part is wrong.
the printing should be inside an if.
0
something like this:
int main() {
int array[10], b=0 , N=10;
for (int i=0; i<N; i++){
cin>>array[i];
if (array[i]<=10)
cout<<"the integers that less than or equal 10 is:"<<b<<endl;
}
return 0;
}