Home > Software engineering >  I've made a code for a assignment but i need a push in the right direction
I've made a code for a assignment but i need a push in the right direction

Time:04-29

i need your guidance for this assignment:

At TEC Ballerup Stadium with room for 500 spectators, football matches are played every Sunday at 10.00. It is amateurs who play and it costs to watch the matches. There is access for adults and children, also spectators who are not members of the club (members of the club get a 10% discount!) A children's ticket costs DKK 30. An adult ticket costs DKK 65. Children only have access with an adult. first enter how many adult tickets and then how many children's tickets you want to buy. There must be a good guide so that the user of the program is not in doubt about what to enter.

a. Once the price has been calculated and displayed, the program must ask if you are a member of the club's association group. Here you can answer yes or no.

b. If you are a member, you get a discount of 10%. Print the discount.

c. There must be two loops (one for each entry of the number of tickets) so that you can order a maximum of 10 children's tickets and 10 adult tickets.

d. Make a printout that also tells how many tickets you have bought in total. So children and adult tickets together.

e. Some individual foreign spectators would like to pay in Euros. Modify the program so that it can also print the total price in EUR. Expect the course at the moment. is 757.34. Make sure to round to the whole Euro as we can not give back in foreign currency.

f. Add Date so that the application always prints the current date at the top right of the screen

So far i've coded this:

int maxNumber = 500;
            int revenueSum = 0;
            string adultBillet;
            string childrenBillet;
            int numberOrdered;
            string numberOrderedString;

            // How many adult tickets?
            Console.WriteLine ("number of adult tickets");
            Console.Write ("how many do you want?");
            adultBillet = Console.ReadLine ();

            // how many child tickets?
            Console.WriteLine ("number of child tickets");
            Console.Write ("how many do you want?");
            childrenBillet = Console.ReadLine ();

            String selection = "1";

            while (choice! = "9")
            {
                Console.WriteLine ("How many adult tickets do you want ??");
                numberOrdered = Convert.ToInt32 (Console.ReadLine ());

                if (numberOrdered == 0)
                {
                    Console.WriteLine ("You will need to purchase at least 1 ticket.");
                }
                else if (number Ordered> 10)
                {
                    Console.WriteLine ("maximum number of adult tickets is 10.");
                }
                else if (numberOrdered> maxNumber)
                {
                    Console.WriteLine ($ "Only {quantityOrder} left");
                }
                else
                {
                    Console.WriteLine ($ "You have decided to purchase {number of Ordered} adult tickets");

                }
                Console.WriteLine ("are you a club member?");
                Console.WriteLine ("please answer YES or NO");
                String Club MemberReply = Console.ReadLine (). ToUpper ();
                
                if (Club Member Answer == "YES")
                {
                    Console.Write (numberOrdered * 65 * 0.9);

                }
                else if (Club MemberReply == "NO")
                {
                   Console.Write(AmountofTickets * 65); 
                }
                else
                {
                    Console.WriteLine("Invalid answer");

i'm stuck on what to do now? It's all, all over the place, but uh I guess I need a loop for adulttickets and kidstickets and how many tickets in total and the euros and dkk's and finally the date

CodePudding user response:

I made a demo for you according to your request, just for your reference.

You can use the following code to set a size for the console first.

Console.SetWindowSize(100, 50);
Console.SetBufferSize(100, 50);

Use this to output the date

Console.CursorLeft = Console.BufferWidth - 10;
Console.Write("{0}\n", DateTime.Now.ToString("yyyy-MM-dd"));

Use int.TryParse to prevent users from entering incorrect information.

There are two main cycles, the purchase of adult tickets for the big cycle and the purchase of children's tickets for the small cycle.

The judgment condition is simpler. Entering the specified character is regarded as yes, otherwise it is regarded as no.

Below is my code:

using System;

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            double adultPrice = 65, kidPrice = 30, totalPrices = 0;
            int tmpTickets = 0, adultTickets = 0, kidsTickets = 0, totalTickets = 0, EurPrices = 0;
            bool adultSuccess = false, kidSuccess = false;
            Console.SetWindowSize(100, 50);
            Console.SetBufferSize(100, 50);
            Console.CursorLeft = Console.BufferWidth - 10;
            Console.Write("{0}\n", DateTime.Now.ToString("yyyy-MM-dd"));
            Console.WriteLine("Welcome Ticket Mall!\n"  
                "AdultPrice 65 DKK,childrenPrice 30 DKK.\n"  
                "You can order a maximum of 10 children's tickets and 10 adult tickets.\n"  
                "A child enters with an adult, so the child ticket cannot be larger than the adult ticket.");
            while (!adultSuccess)
            {
                Console.WriteLine("Please enter the number of adult tickets.");
                if (adultSuccess = int.TryParse(Console.ReadLine(), out tmpTickets))
                {
                    if (tmpTickets < 0 || tmpTickets > 10)
                    {
                        Console.WriteLine("input error!please enter again!");
                        adultSuccess = false;
                    }
                    else if (tmpTickets == 0)
                    {
                        Console.WriteLine("Thanks for using, bye.");
                    }
                    else
                    {
                        adultTickets = tmpTickets;
                        Console.WriteLine("Do you need to buy a child ticket?\n"  
                            "Enter 'Y' or 'y' to go to the next step.");
                        string tmp = Console.ReadLine();
                        if (tmp != "Y" && tmp != "y")
                        {
                            break;
                        }
                        else
                        {
                            while (!kidSuccess)
                            {
                                Console.WriteLine("Please enter the number of kids tickets.");
                                if (kidSuccess = int.TryParse(Console.ReadLine(), out tmpTickets))
                                {
                                    if (tmpTickets < 0 || tmpTickets > adultTickets)
                                    {
                                        Console.WriteLine("input error!please enter again!");
                                        kidSuccess = false;
                                    }
                                    else
                                    {
                                        kidsTickets = tmpTickets;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            Console.Clear();
            Console.CursorLeft = Console.BufferWidth - 10;
            Console.Write("{0}\n", DateTime.Now.ToString("yyyy-MM-dd"));
            totalPrices = adultTickets * adultPrice   kidsTickets * kidPrice;
            totalTickets = adultTickets   kidsTickets;
            Console.WriteLine($"You have decided to purchase {adultTickets} adult tickets {kidsTickets} kid tickets\n"  
                $"Total {totalTickets} tickets , {totalPrices}   DKK ");
            Console.WriteLine("are you a club member?\n"  
                "Enter 'Y' or 'y' as a member.");
            var tmp2 = Console.ReadLine();
            if (tmp2 != "Y" && tmp2 != "y")
            {
                //1 Danish Krone is equal to 0.13 EUR now
                EurPrices = Convert.ToInt32(totalPrices * 0.13);
                Console.WriteLine($"You need to pay {totalPrices} DKK or {EurPrices} EUR! ");
            }
            else
            {
                totalPrices = totalPrices * 0.9;
                EurPrices = Convert.ToInt32(totalPrices * 0.13);
                Console.WriteLine($"As a member! You need to pay {totalPrices} DKK or {EurPrices} EUR !");
            }
            //Pause
            Console.ReadLine();
        }
    }
}

Here is a screenshot of my demo:

enter image description here

enter image description here

  • Related