unable to use while proparly [Answered]

Ddaniel111/19/2022
.
Ddaniel111/19/2022
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);

;
}
}
}
TTheRanger11/19/2022
what?
TTheRanger11/19/2022
yeah ur while loop will run forever if the user input any number other than -1
Ddaniel111/19/2022
yeah but once i enter one number it wont let me type anything else
TTheRanger11/19/2022
well ofcourse, since ur program is stuck in the while loop
Ddaniel111/19/2022
so how do i fix it
TTheRanger11/19/2022
uh what do u need the while loop for
Ddaniel111/19/2022
{
count++;
sum = sum + num;
}
Ddaniel111/19/2022
this is inside the while loop
Ddaniel111/19/2022
so how can the whole program be stuck
Ddaniel111/19/2022
i got a school asigment and it goes something like this
TTheRanger11/19/2022
because you never break out of the while loop
TTheRanger11/19/2022
ur while loop will run as long as num isnt -1
Ddaniel111/19/2022
"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"
TTheRanger11/19/2022
and since you never modified num in the while loop, it will run forever
Ddaniel111/19/2022
yeah but i can only enter 1 number
Ddaniel111/19/2022
so how should i modify it ?
TTheRanger11/19/2022
try to ask for user input in the while loop
Ddaniel111/19/2022
yeah well it works now besides one small problem
Ddaniel111/19/2022
the avrage is not proparly caculated
TTheRanger11/19/2022
average's formula is usually like this right? sum / count
Ddaniel111/19/2022
you just fixed everything in less then 10 minutes 👍
TTheRanger11/19/2022
if ur done type/close to mark this thread as answered
AAccord11/19/2022
✅ This post has been marked as answered!