Hello guys,
cant remember if really newb questions go here.
anyway, i am writing a basic times table program
asks the user for number between 1 and 12 then spits out that numbers times table, but im having a problem, why cant number be carried through the do while loop?
i would have thought that public int number would be readable throughout the program?
my last line Console.WriteLine(number); , number is just not avilable.
cant remember if really newb questions go here.
anyway, i am writing a basic times table program
asks the user for number between 1 and 12 then spits out that numbers times table, but im having a problem, why cant number be carried through the do while loop?
i would have thought that public int number would be readable throughout the program?
my last line Console.WriteLine(number); , number is just not avilable.
C#:
using System;
namespace MuliplicationTable
{
class Program
{
public int number;
static void Main(string[] args)
{
Console.WriteLine("Multiplication Tables");
Console.WriteLine("*********************");
bool hasValidNumber = false;
do
{
Console.WriteLine("Enter number between 1 and 12:");
int number = Console.Read();
if (number > 1 && number < 12)
{
hasValidNumber = true;
} else
{
hasValidNumber = false;
}
} while (!hasValidNumber);
Console.WriteLine(number);
}
}
}