Can any one help me? I am new to programming..
I am creating a console output to let a user enter a series of random numbers. The letters 'n' or 'N' will break the loop, and display the sum and average.
I can do most of this, execpt the only part confusing me is converting the char to an int, as entering a 'n' or 'N', will break it, as it is an int.
here is my code so far:
class MyClass
{
static void Main(string[] args)
{
int num = 0;
int i = - 1;
int sum = 0;
int avg = 0;
do
{
Console.WriteLine("Enter N to quit");
num = char.Parse(Console.ReadLine());
i++;
if (num == 'n')
{
break;
}
else
{
sum = sum + num;
}
} while (num != 'n' || num != 'N');
avg = sum / i;
Console.WriteLine("\nThe amount of numbers entered was: " + i);
Console.WriteLine("\nSum is " + sum);
Console.WriteLine("\naverage is " + avg);
Console.WriteLine("\nProgram Finsihed");
Console.WriteLine("Press any key to continue...");
Console.ReadLine();