Question

In: Computer Science

Please debug this by fixing all the mistakes so it will compile in C# // Program...

Please debug this by fixing all the mistakes so it will compile in C#



// Program prompts user for any number of values
// (up to 20)
// and averages them

using System;
public class DebugFive04
{
    public static void Main()
    {
        const int QUIT = 999;
        int[] numbers = new int[20];
        int x;
        int num;
        double average;
        double total;
        string inString; // intString
        Console.Write("Please enter a number or " +
           QUIT + " to quit...");
        inString = Console.ReadLine();
        num = Convert.ToInt32(inString); // inString
        x = 0;
        while ((x < numbers.Length))
        {
            numbers[x] = num;
            ++x;
            total = +numbers[x]; // =+ not +=
            Console.Write("Please enter a number or " +
               QUIT + " to quit...");
            inString = Console.ReadLine();
            numbers = Convert.ToInt32(inString);
        }
        Console.WriteLine("The numbers are:");
        for (int y = 0; y < x; ++y)
            Console.Write("{0,6}", numbers[y]);
        average = total / numbers.Length;
        Console.WriteLine();
        Console.WriteLine("The average is {0}", average);
    }
}

Solutions

Expert Solution

using System;
public class DebugFive04
{
public static void Main()
{
const int QUIT = 999;
int[] numbers = new int[20];
int x;
int num;
double average;
double total=0;
string inString; // intString
  
  
x = 0;
while ((x < numbers.Length))
{
  
Console.Write("Please enter a number or " + QUIT + " to quit...");
inString = Console.ReadLine();
num = Convert.ToInt32(inString); // inString
if(num==999)
break;
numbers[x] = num;
  
total += numbers[x]; // =+ not +=
x++;

}
Console.WriteLine("The numbers are:");
for (int y = 0; y < x; ++y)
Console.Write("{0,6}", numbers[y]);
average = total / x;
Console.WriteLine();
Console.WriteLine("The average is {0}", average);
}
}


Related Solutions

please debug this by fixing all the mistakes in C# // Creates a BoatLicense class //...
please debug this by fixing all the mistakes in C# // Creates a BoatLicense class // And instantiates three BoatLicense objects // The price of a licence is $25 if the boat motor is 50 HP or under // and $38 if the HP is over 50 // Boat licenses are issued with numbers starting with 200801 using System; public class DebugSeven4 {    public static void Main()    {       const int STARTINGNUM = 200801;       BoatLicense[] license =...
please debug this by fixing all the mistakes in C#: // Creates a Breakfast class //...
please debug this by fixing all the mistakes in C#: // Creates a Breakfast class // and instantiates an object // Displays Breakfast special information using System; public class DebugSeven2 {    Breakfast special = new Breakfast("French toast", 4.99);    //Display the info about breakfast    Console.WriteLine(Breakfast.info);    // then display today's special    Console.WriteLine("Today we are having {0} for {1}",       special.Name, special.Price.ToString("C2")); } class Breakfast {    // info is class field    public static string info =...
please debug this code by fixing all the mistakes. thank you. // Creates a HomeworkAssignment class...
please debug this code by fixing all the mistakes. thank you. // Creates a HomeworkAssignment class // instantiates two objects // and prompts the user for infromation about two courses using System; public class DebugSeven1 {     public static void Main()     {         HomeworkAssignment course1;         HomeworkAssignment course2;         string entryString;         int exercises;         // Get info for first class         Console.Write("What class do you have homework for? ");         entryString = Console.ReadLine(); // Fixed .ReadLine         course1.ClassName...
please debug this so that it will compiler: C# // Uses PrintWebAddress method three times using...
please debug this so that it will compiler: C# // Uses PrintWebAddress method three times using System; public class DebugSix2 {    public void Main()    {       PrintWebAddress();       Console.WriteLine("Shop at Shopper's World");       PrintWebAddresses();       Console.WriteLine("The best bargains from around the world");       PrintWebAddress;    }    public void PrintWebAddress()    {       Console.WriteLine(------------------------------");       Console.WriteLine(Visit us on the web at:");       Console.WriteLine(www.shoppersworldbargains.com");       Console.WriteLine(******************************");    } }
Take all the methods from this program and put it into single program and compile, and...
Take all the methods from this program and put it into single program and compile, and then test the program with some expressions. Should have two files: Lex.java and a output.txt file package lexicalanalyser; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.logging.Level; import java.util.logging.Logger; enum CharacterClass{ LETTER(0), DIGIT(1), UNKNOWN(99), EOF(-1); private int value; private CharacterClass(int value){ this.value = value; } public int getValue(){ return value; } } enum TokenCodes{ INT_LIT(10), IDENT(11), ASSIGN_OP(20), ADD_OP(21), SUB_OP(22),...
This programming assignment will consist of a C++ program. Your program must compile correctly and produce...
This programming assignment will consist of a C++ program. Your program must compile correctly and produce the specified output. Please note that your programs should comply with the commenting and formatting described in the Required Program Development Best Practices document that has been discussed in class and is posted to the eLearning system. Please see this descriptive file on the eLearning system for more details. The name to use in the main configuration screen text box Name: [ ] in...
C++ program, I'm a beginner so please make sure keep it simple Write a program to...
C++ program, I'm a beginner so please make sure keep it simple Write a program to read the input file, shown below and write out the output file shown below. Use only string objects and string functions to process the data. Do not use c-string functions or stringstream (or istringstream or ostringstream) class objects for your solution. Input File.txt: Cincinnati 27, Buffalo 24 Detroit 31, Cleveland 17 Kansas City 24, Oakland 7 Carolina 35, Minnesota 10 Pittsburgh 19, NY Jets...
USE C++ and please keep program as simple as possible and also comment so it is...
USE C++ and please keep program as simple as possible and also comment so it is easy to understad Create a structure called time. Its three members, all type int, should be called hours, minutes, and seconds. Write a program that prompts the user to enter a time value in hours, minutes, and seconds. This should be in 12:59:59 format. This entire input should be assigned first to a string variable. Then the string should be tokenized thereby assigning the...
in C++ Compile and run the program for the following values: r = 2 Cm, h...
in C++ Compile and run the program for the following values: r = 2 Cm, h = 10 Cm. The answer should be: The cross section area of the cylinder is 3.8955634 c The side area of the cylinder is 19.474819 inch-sqr Did you get the same answer? Explain the reason for such an error and fix the problem. Modify the previous program to include a new function called total_area, that computes the total suface area of a cylinder. The...
6. Write a program in C programming (compile and run), a pseudocode, and draw a flowchart...
6. Write a program in C programming (compile and run), a pseudocode, and draw a flowchart for each of the following problems: a) Obtain three numbers from the keyboard, compute their product and display the result. b) Obtain two numbers from the keyboard, and determine and display which (if either) is the smaller of the two numbers. c) Obtain a series of positive numbers from the keyboard, and determine and display their average (with 4 decimal points). Assume that the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT