Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
C#
Console.WriteLine("Please enter Name");
            name = Console.ReadLine();
            Console.WriteLine("{0} has been stored", name);
            Console.WriteLine("Enter the License plate Number");
            Console.WriteLine("");
            LicenseplateNumber = Console.ReadLine();
            int numcar1, numcar2, total, result;
            int[] num = new int[2];
            num[0] = 1;
            num[1] = 2;
            Console.WriteLine("Please enter how many cars");
            numcar1 = Int32.Parse(Console.ReadLine());
            Console.WriteLine("Total space=2");
            total = 2;
            result = total - numcar1;
            Console.WriteLine("{0} space is left", result);


ok i have looked at the articles and still cant figure where to put the loop. I want to loop so that i can fill for 2. and when its done how do i write the space is full. do i write while (result <= 2). help?
Posted
Updated 3-Nov-14 13:13pm
v2
Comments
Sergey Alexandrovich Kryukov 3-Nov-14 22:19pm    
The question makes no sense. You cannot explain what you want to achieve with the code, if you don't know how to write the code correctly. Therefore, you need to explain in in some other way. :-)
—SA

it really depends on your logic and what you want to achieve as to what sort of loop you need to use - and what sort of 'end' condition you need - maybe

C#
do
{

    // Some Statements

} while (some condition);



is what you need, but its a bit hard to tell

What are you trying to achieve ? there's sfa point asking us where to put the loop if you cant explain what you're trying to do
 
Share this answer
 
See if you can fill in what's missing here ... where you see ???? ... and make it work:
C#
class Program
{
    static int numberOfSpaces = 3;

    static int currentCar = 0;

    static int spacesFree = numberOfSpaces;

    static string[,] currentCarsParked = new string[numberOfSpaces, 2];
        
    static void Main(string[] args)
    {
        string name, license;

        while (spacesFree > 0)
        {
            Console.Clear();
            ReportStatus();

            Console.WriteLine();
            Console.Write("Please enter Name: ");
            name = Console.ReadLine();

            Console.Write("Enter the License plate Number: ");
            license = Console.ReadLine();

            currentCarsParked[????, 0] = name;
            currentCarsParked[????, 1] = license;
            currentCar++;

            spacesFree--;           
        }

        Console.Clear();

        Console.WriteLine("Parking Lot is full !");
        Console.WriteLine();

        ReportStatus();

        Console.WriteLine();
        Console.WriteLine("Press any key to exit");

        Console.ReadKey();
    }

    private static void ReportStatus()
    {
        Console.Write("Current Parked Cars: {0}", currentCar);
        Console.WriteLine(": Spaces available: {0}", spacesFree);
        Console.WriteLine();

        for (int i = 0; i < ????; i++)
        {
            Console.Write("Space: {0}: Car #{1}", i + 1, currentCarsParked[i, 0]);
            Console.WriteLine(" License: {0}", currentCarsParked[i, 1]);
        }
    }
}
 
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