I am practicing my looping, specifically doing while loop, here is it below, but for some reason, what it is suppose to do if you enter a number exactly 20 or above, it asks please enter another number less and you enter it in, then it does a cound up to 20, so far got the number to go if you press something less than 20 but anything 20 or above, it just kicks out: can you please correct the program and explain what i did wrong for future reference would be appreciated.
namespace ConsoleApplication1
{
class Program
{
/*
static string write()
{
string mystring;
Console.WriteLine("Please enter first name");
mystring = Console.ReadLine();
return mystring;
}
*/
static void Main(string[] args)
{
int num1 = 20;
int num2;
Console.WriteLine("Please enter a number less than 20: ");
num2 = int.Parse(Console.ReadLine());
if (num2 >= num1)
Console.WriteLine("Please enter another number");
while (num2 < num1)
{
num2++;
Console.WriteLine(num2);
}
Console.ReadKey();


Sign In
Create Account


Back to top









