Question: Need help trying to fix my C# code please! The following is the assignment question: Write a console app called CollectPossumSizes that continuously prompts the

Need help trying to fix my C# code please!

The following is the assignment question:

Write a console app called CollectPossumSizes that continuously prompts the user to enter sizes of possums (in inches) until the sentinel value of 0 is entered. You must use a loop to get these possum sizes from the user. As you get each possum size, count it and accumulate it. In other words, use a counter variable and add 1 to it each time you get a possum value. Similarly, use an accumulator variable and add the possum size to it each time you get one. After the loop is done, output the number of possum values collected, the sum of possum values, and the average possum size (in inches).

Here is my code so far:

using System; using static System.Console;

namespace CollectPossumSizes { class Program { static void Main(string[] args) { double average; int sum, count; const double INC_RATE = 1; string inputString, userInput = ""; double possumSize; char response; Write("Enter possum size in inches (0 to stop): "); inputString = ReadLine(); response = Convert.ToChar(inputString); while (userInput == "") { WriteLine("Possum size is {0}", possumSize.ToString("C")); possumSize = possumSize + INC_RATE; Write("Enter possum size in inches (0 to stop): "); inputString = ReadLine(); response = Convert.ToChar(inputString); }

average = (double)sum / count; Console.WriteLine(" Number of possum values collected: " + count); Console.WriteLine("The sum of possum values: " + sum); Console.WriteLine("The average possum size (in inches): " + Math.Round(average, 2)); } } }

it is really messy but I need help trying to fix it. I saw similar questions that were answered here but they failed to add 1 to each time a possum value was entered. Please help me fix/rewrite my code if possible. Thanks!!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!