0

I have an array of 20 elements with numbers between 1 and 8. I need a for loop that will give me the number of elements greater than 1???

4
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by Grn Xtrm
0

Create another variable to store the number of 1's. You go through all elements of the array and each time it equals 1 you increment that variable by 1.

You could think of that by yourself ain't that hard.

0

Create another variable to store the number of 1's. You go through all elements of the array and each time it equals 1 you increment that variable by 1.

You could think of that by yourself ain't that hard.

I get that I just don't know how to put it into a for loop? I'm very new at this and in need of help. I don't know exactly what to put in the for loop and where?

0

I get that I just don't know how to put it into a for loop? I'm very new at this and in need of help. I don't know exactly what to put in the for loop and where?

I used sum for my variable but it was telling me where the 1's were in the array instead of adding them up.

0

I'll give you a hint to what I'd do.
Use a for loop to iterate through the array
Use an if statement to check if the number is greater than 1.
You'll need to include a counter which you will increment every time the if statement is successful.
This is not a very difficult problem. Use my advice and post back with your best effort. Good luck.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.