0

I'm trying to make the program able to receive more than one input and then give the results of all the imputs together. Sofar, rightnow I'm only able to input one number and the program will immediately print out the result. I want to continue to imput until I press y or n and then print out the results. Any help will be appreciated. What I have at this moment is the following.

[using System;
using System.Collections.Generic;
using System.Text;


namespace ConsoleApplication00000007
{
class Program
{
public void Go()
{
int n;
double sum = 0.0, sumsquare = 0.0, mean = 0.0, var = 0.0;


Console.Write("Enter an integer: ");
n = int.Parse(Console.ReadLine());
for (int i = 1; i <= n; i++)
{
sum = sum + i;
sumsquare = sumsquare + i * i;
}
if (n > 0)
{
mean = sum / n;
var = (sumsquare - sum * sum / n) / n;


Console.WriteLine("The mean = " + mean);
Console.WriteLine("The variance = " + var);
}


}
static void Main(string[] args)
{
new Program().Go();
}
}
}]

Edited by happygeek: fixed formatting

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Van Gogh
0

before calling the method which compute the variance and the mean

string n = Console.ReadLine();
if( n == "y")
// exit
else
//parse and compute
0

Thanks Ramy,

I was also thinking of placing a while loop to continue accepting numbers until I ress a certain key to stop anc compute all and display the results.

I'll give it a try.
Any help is always appreciated.

Vincent

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.