17 Replies
using System;
namespace school_work_28
{
class Program
{
static void Main(string[] args)
{
int num, sum = 0, count = 0;
double avrage = 0;
Console.WriteLine("enter num to end enter -1");
num = int.Parse(Console.ReadLine());
while (num != -1)
{
count++;
sum = sum + num;
}
Console.WriteLine("enter num");
num = int.Parse(Console.ReadLine());
avrage = count % sum;
Console.WriteLine("the avrage is=" + avrage);
;
}
}
}
what?
yeah ur while loop will run forever if the user input any number other than -1
yeah but once i enter one number it wont let me type anything else
well ofcourse, since ur program is stuck in the while loop
so how do i fix it
uh what do u need the while loop for
{
count++;
sum = sum + num;
}
this is inside the while loop
so how can the whole program be stuck
i got a school asigment and it goes something like this
because you never break out of the while loop
ur while loop will run as long as
num
isnt -1
"write a program that takes in numbers once number -1 is taken in the program shuts down the prgoram needs to caculate the avrage out of all the numbers and display it on screen"
and since you never modified
num
in the while loop, it will run foreveryeah but i can only enter 1 number
so how should i modify it ?
try to ask for user input in the while loop
yeah well it works now besides one small problem
the avrage is not proparly caculated
average's formula is usually like this right?
sum / count
you just fixed everything in less then 10 minutes 👍
if ur done type
/close
to mark this thread as answered✅ This post has been marked as answered!