C# C# Basics (Retired) Perfect Wrap Up

Ankit Biswas
Ankit Biswas
280 Points

Average

Averager Repeatedly prompt the user for numbers. Add all of the numbers together. When the user types in “done”, print the average of all of the numbers by dividing the total by the number of numbers entered.?

treehouse:~/workspace$ mcs Program.cs && mono Program.exe Enter a number or type "done" to see the average: 5.5 Enter a number or type "done" to see the average: bogus That is not valid input. Enter a number or type "done" to see the average: 4.2 Enter a number or type "done" to see the average: 99 Enter a number or type "done" to see the average: done Average: 36.2333333333333

Please Tell me the write code for it?

1 Answer

Steven Parker
Steven Parker
170,315 Points

If that's a sample of the input to and output from your program, it appears to be functioning correctly already.

Can you elaborate a bit about what's making you think there's a problem with it?

Also, when you need help with coding, be sure to show your current code with the question (or include a link to a workspace snapshot).

Ankit Biswas
Ankit Biswas
280 Points

Here is my Code /PROMPT USER FOR A VALUE. Console.WriteLine("Please enter your name!"); string userName = Console.ReadLine(); Console.WriteLine("Wellcome " + userName + "!"); while(true) { double numbertotal = 0; int numbers = 0; Console.Write("Please enter a value or enter \"done\" to exit: "); string userInput = Console.ReadLine();

if (userInput.toLower() == "done") { break; } else { try { numbertotal += double.Parse(userInput); // Removed var keyword numbers++; } catch(FormatException){ Console.WriteLine("This number is Not valid. Please try again!"); continue; } } Console.WriteLine("The average of the values is: " + numbertotal / numbers); } } } } And i get this error error CS2001: Source file `Program.
cs' could not be found
Compilation failed: 1 error(s), 0 w
arnings

Steven Parker
Steven Parker
170,315 Points

Not finding the code is different from having a code error. But how did you produce the output shown above?

Anyway for configuration issues like this sharing the entire project will be the best way to check it. Make a snapshot (note: not "screenshot") of your workspace and post the link to it here.