There is something wrong with my code...

even i put a valid license the display showing
is the line 30-33 supposed to be line 28.

how to display the not character in line 30 instead of counting how many.

Console.WriteLine("{0, 40}", "ICA17 - License Plate Checker");

            string sLicence;
            string sAgain;
            int ilicense = 0;
            int iUpper = 0;             
            int iLower = 0;             
            int iNotValid = 0;

            do
            {
                Console.Write("\nEnter a license plate number: ");
                sLicence = Console.ReadLine();
            
                foreach (char cCh in sLicence)
                {
                    if (char.IsDigit(cCh))
                        ++ilicense;
                    else if (char.IsUpper(cCh))
                        ++iUpper;
                    else if (char.IsLower(cCh))
                        ++iLower;
                    else
                        iNotValid++;
                }

                if ((iUpper > 1) && (iLower > 1) && (ilicense > 1) && (iNotValid > 1) && (sLicence.Length > 6))
                    Console.WriteLine("\n{0} is a valie license plate.", sLicence);
                else
                    Console.WriteLine("The {0} character is not valid.", iNotValid);
                    Console.WriteLine("There was an incorrect number of digits.");
                    Console.WriteLine("There was an incorrect number of letters.");
                    Console.WriteLine("There is a lowercase letter in the plate.");

                Console.Write("\nRun again? \"yes\" to enter another plate: ");
                sAgain = Console.ReadLine();
            }
            while(sAgain == "yes");

            Console.ReadLine();

Recommended Answers

All 3 Replies

You don't reset your counts when you enter a new plate. Move lines 5-8 to right inside the do loop.

Your if statement in line 27 needs some work, as does the else part.

i know my code need some work, that is why i post it here, for help...

Ask yourself "What is the criteria for a good license plate". Then check for that in your if statement.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.