I’m trying to do my debugging homework, there is something wrong with my code that I couldn’t figure out. when I enter some numbers “the numbers are” keep going till 19 even if I enter less than that .any help would be appricated.

I'm trying to do my debugging homework, there is something wrong with my code that I couldn't figure out. when I enter some numbers "the numbers are" keep going till 19 even if I enter less than that .any help would be appricated.

const int QUIT = 999;

int[] numbers = new int[19];

int x = 0;

int num;

double average;

double total = 0;

string inString;

Write(“Please enter a number or ” + QUIT + ” to quit…”);

inString = ReadLine();

num = Convert.ToInt32(inString);

while ((x < numbers.Length) && num != QUIT)

{

numbers[x] = num;

total += numbers[x];

++x;

if (x < numbers.Length)

{

Write(“Please enter a number or ” + QUIT + ” to quit…”);

inString = ReadLine();

num = Convert.ToInt32(inString);

}

}

WriteLine(“The numbers are:”);

for ( x = 0; x < numbers.Length; ++x)

{

Write(“{0,6}”, numbers[x]);

}

average = total / numbers.Length;

WriteLine();

WriteLine(“The average is {0}”, average);

this is my coding result.

this is what i suppose to get.

submitted by /u/samreddittt
[link] [comments]

Leave a Reply