Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,34 @@
|
|||
namespace RosettaCode
|
||||
{
|
||||
class CSharpRecurringRainfall
|
||||
{
|
||||
static int ReadNextInput()
|
||||
{
|
||||
System.Console.Write("Enter rainfall int, 99999 to quit: ");
|
||||
string input = System.Console.ReadLine();
|
||||
|
||||
if (System.Int32.TryParse(input, out int num))
|
||||
{
|
||||
return num;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Console.WriteLine("Invalid input");
|
||||
return ReadNextInput();
|
||||
}
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
double currentAverage = 0;
|
||||
int currentEntryNumber = 0;
|
||||
|
||||
for (int lastInput = ReadNextInput(); lastInput != 99999; lastInput = ReadNextInput())
|
||||
{
|
||||
currentEntryNumber++;
|
||||
currentAverage = currentAverage + (1.0/(float)currentEntryNumber)*lastInput - (1.0/(float)currentEntryNumber)*currentAverage;
|
||||
System.Console.WriteLine("New Average: " + currentAverage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue