Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help debugging this program. I have figure out most of it but it will sti

ID: 3664596 • Letter: I

Question

I need help debugging this program. I have figure out most of it but it will still not work

// Program prompts user for any number of values
// (up to 20)
// and averages them
using System;
using static System.Console;
class DebugSix04
{
    public static void Main()
    {
        const int QUIT = 999;
        int[] numbers = new int[];
        int x;
        int num;
        double average;
        double total = 0;
        string inString;
        Console.Write("Please enter a number or " +
           QUIT + " to quit...");
        inString = ReadLine();
        num = Convert.ToInt(inString);
        while ((x < numbers.Length) && num == QUIT)
        {
            numbers[x] = num;
            total += numbers[x];
            ++x;
            Write("Please enter a number or " +
               QUIT + " to quit...");
            inString = readLine();
            num = Convert.ToInt32(inString);
        }
        WriteLine("The numbers are:");
        for (int y = 0; y < x; ++x)
            Console.Write("{0,6}", numbers[y]);
        average = total / z;
        WriteLine();
        WriteLine("The average is {0}", avge;
    }
}

Explanation / Answer


// I have used Java Programming
import java.util.Scanner;

class DebugSix04
{
public static void main(String arg[])
{
final int QUIT = 999;
int[] numbers = new int[20];
int x;
int num;
double average;
double total = 0;
Scanner sc = new Scanner(System.in); // to read input
System.out.println("Please enter a number or " +
QUIT + " to quit...");
num = sc.nextInt(); // reading integer, not string
x = 0;
while ((num != QUIT) && x < 20) // reading max of 20 numbers
{
numbers[x] = num;
total += numbers[x]; // finding total
++x;
System.out.println("Please enter a number or " +
QUIT + " to quit...");
num = sc.nextInt();
}
System.out.println("The numbers are:");
for (int y = 0; y < x; ++x)
System.out.print(numbers[y]+" ");
average = total / x;
System.out.println();
System.out.println("The average is :"+ average);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote