Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Public Finance Fundamentals

Authors: K. Moeti

3rd Edition

148512946X, 9781485129462

Students also viewed these Databases questions