Array c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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; } }

8th Jan 2017, 11:31 PM
anfala_alali
anfala_alali - avatar
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.
8th Jan 2017, 11:52 PM
DFX
DFX - avatar
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; }
9th Jan 2017, 12:05 AM
DFX
DFX - avatar