Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the stuff I did below, everything is fine but:
Console.WriteLine("You are a child");
(and all the other ones similar to this^) say there is an error after the semicolon

C#
namespace B13
{
    class Program
    {
        static void Main(string[] args)
        {
            int age = 1;
            while (age >= 50)

            {
                Console.WriteLine("Enter your age");


                age = Convert.ToInt32(Console.ReadLine());
                {

                    if (age > 29)
                    {
                        do


                            Console.WriteLine("You are old!");
                    }
                    else
                    {
                        if (age == 19)
                            while (age != 30)
                                do
                                    Console.WriteLine("You are getting old");




                     else
                        {
                            if (age == 13)
                                while (age != 19)
                                    do
                                        Console.WriteLine("You are a teenager");


                       else
                            {
                                if (age < 13)

                                    do
                                        Console.WriteLine("You are a child");
                    }
                            Console.WriteLine(age);
                            Console.ReadKey();


                        }
                    }
                }
            }
        }
    }
}


What I have tried:

I tried removing the semicolon, but i don't think that is what I am supposed to do, I am very new to this, and very confused. Can someone pleaasee help me understand what I did wrong. Thank You
Posted
Updated 18-Oct-17 16:54pm
v2

The following will compile, but the code has semantic issues:
If you enter age of 19, or 13 it will loop forever. Inputs 14,15,16,17,18 will print nothing. I don't think you want to use while. Probably you want something like
if (age >=14 and age <= 19) Console.WriteLine("You are a teenager");


C#
using System;

namespace B13
{
    class Program
    {
        static void Main(string[] args)
        {
            int age = 1;
            while (age >= 50)

            {
                Console.WriteLine("Enter your age");

                age = Convert.ToInt32(Console.ReadLine());
                {
                    if (age > 29)
                    {
                        Console.WriteLine("You are old!");
                    }
                    else
                    {
                        if (age == 19) while (age != 30) Console.WriteLine("You are getting old");

                        else
                        {
                            if (age == 13) while (age != 19) Console.WriteLine("You are a teenager");

                            else
                            {
                                if (age < 13) Console.WriteLine("You are a child");
                            }
                            Console.WriteLine(age);
                            Console.ReadKey();
                        }
                    }
                }
            }
        }
    }
}
 
Share this answer
 
What are supposed to be all those while and do scattered everywhere?
Those are not random statements!

Your code is very confuse, you should tell us what is supposed to do your code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900