Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
231,275 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
231,275 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.