I need to make a loop that runs for 3 times and a switch for three age groups 0-10 11-20 and 21-65 with the following code:
class Program
{
private static object N;
static void Main(string[] args)
{
string answer;
{
Console.WriteLine("please enter your name:");
string name = Console.ReadLine();
Console.WriteLine("please enter your surname:");
string surname = Console.ReadLine();
Console.WriteLine("please enter your age:");
string age = Console.ReadLine();
Console.WriteLine("please enter your adress:");
string adress = Console.ReadLine();
Console.WriteLine("hallo,{0} {1},veel sucess met C#", name, surname);
Console.WriteLine("zijn deze gegevens juist? J/N");
answer = Console.ReadLine();
}
while(answer == "N");
}
}
I tried some things to test the age, but I always got errors. Also, I don’t know how to write the loop code correctly.
Can somebody please point me in the right direction for both problems?
Sorry for my bad English I’m Dutch.
NOTE: the OP mentioned under one of the answers that this is not a homework assignment.
Switch statements operate on specific values, not ranges, so you’d want to use a series
ifstatements instead.Use a counter (declared outside of the loop and incremented on every execution) to determine how many times the loop has run (or use a
forloop).Edit