Updated on September 25, 2018 in [C] Beginner
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on July 20, 2017

i ‘am having some issues with my homework.  the problem is Create a public static method int CountOddNumbers(int[] myArray) which returns the quantity of odd numbers that exist in myArray.

my code is:

public static int CountOddNumbers(int[] myArray){

for(int x = 0; x < myArray.Length; x++){

if(myArray[x] % 2 == 0){
Console.WriteLine(“{0} “, myArray[x]);
return myArray;



and i get the error cannot convert type int[] to int 

any help? 🙁

  • Liked by
0 on July 21, 2017

so ‘myArray’ is an array of ints, not an actual int. It’s like a bucket full of ints.
Your function is said to return a single int as a return value, and you’re returning the bucket.
What it sounds like your task is to do though, is to return the answer to the question, “How many of the numbers in my bucket are odd numbers?”
there are a couple of ways you could do this, but i think the simplest is for you to create a new variable which increments itself whenever your if statement detects an odd number.
I think you can see where this is going from here.

  • Liked by