Question school

hiseiba

New member
Joined
Oct 8, 2022
Messages
2
Programming Experience
Beginner
Hello everyone I was making my task for school and I really don't understand the problem of my codes can anyone help me

school task:
Design a console application that calculates how much someone has to pay for a cinema ticket.
The full price of a cinema ticket is EUR 13.70.
Based on age, the price is determined:
Younger than 5: free;
Between 5 and 12: half price;
Between 13 and 54: full price;
55+: free

MY codes:
C#:
//declaration variables
            const double cdblFullPriceTicket = 13.70;
            double dblEndPriceTicket;
            int int Age;

            dblEndPriceTicket = 0;

            //entry
            Console.Write("How old are you: ");
intAge = Convert.ToInt32(Console.Read()); ;




            if (intAge < 5)
            {

                //output
                Console.WriteLine();
                Console.Write("your cinema ticket is free.");
            }
            else if (intAge >= 5 && intAge<= 12)
            {
                //calculation
dblEndPriceTicket = cdblFullPriceTicket / 2;

                //output
                Console.WriteLine();
                Console.Write("you must pay " + Math.Round(dblEindPriceTicket, 2).ToString() + "EUR.");
            }
            else if (intAge >= 13 && intAge <= 54)
            {
                //calculation
                dblEndPriceTicket = cdblFullPriceTicket;

                //export
                Console.WriteLine();
                Console.Write("you must pay " + Math.Round(dblEindPriceTicket, 2).ToString() + "EUR.");
            }
            else if (intAge >= 55)
            {

                //output
                Console.WriteLine();
                Console.Write("your cinema ticket is free.");
            }
            else
            {
                Console.WriteLine();
                Console.Write("you don't enter any data");
            }


            Console.ReadKey();
 
Last edited by a moderator:
Welcome to the forum. In the future, please make sure to put your code in code tags.

What specific problem are you experiencing?
 
Only reading your code on a phone, so I may miss some things, but the only thing that really stands out is line 4 where there is an extra space between intAge.

Anyway, be aware that using Hungarian notation for C# code is against the C# naming conventions. It's those VB6 programmers transitioning to VB.NET and then C#, as well as C/C++ Windows programmers moving to C# which seem to try to perpetuate it.
 
C#:
 //declaration variables
            double cdblFullPriceTicket = 13.70;
            // You not need to use a const because you arnt changeing the Value of cdblFullPriceTicket
            
            int Age = 0;
            double dblEndPriceTicket;
            
            dblEndPriceTicket = 0;

            //entry
            Console.Write("How old are you: ");
            string tempValue = Console.ReadLine();//Use this to read any String
            Age = Convert.ToInt32(tempValue); //If that string can be converted to an Int32 it Convert it and set it to Age
            // I found an problem that age is allways 55 (if you type in 7). and with this line of code before you can change it. That now the Age will be showen right




            if (Age < 5)
            {

                //output
                Console.WriteLine();
                Console.Write("your cinema ticket is free.");
            }
            else if (Age >= 5 && Age <= 12)
            {
                //calculation
                dblEndPriceTicket = cdblFullPriceTicket / 2;

                //output
                Console.WriteLine();
                Console.Write("you must pay " + Math.Round(dblEndPriceTicket, 2).ToString() + "EUR.");
            }
            else if (Age >= 13 && Age <= 54)
            {
                //calculation
                dblEndPriceTicket = cdblFullPriceTicket;

                //export
                Console.WriteLine();
                Console.Write("you must pay " + Math.Round(dblEndPriceTicket, 2).ToString() + "EUR.");
            }
            else if (Age >= 55)
            {

                //output
                Console.WriteLine();
                Console.Write("your cinema ticket is free.");
            }
            else
            {
                Console.WriteLine();
                Console.Write("you don't enter any data");
            }

            
            Console.ReadKey();
i found some Errors by you also im writing as Comments the Mistakes and how to prevent it
 
Don't use Console.Read() when youre learning; it doesn't do what you think, and will give you unexpected results. Use Console.ReadLine() instead
 
Hello everyone I was making my task for school and I really don't understand the problem of my codes can anyone help me

school task:
Design a console application that calculates how much someone has to pay for a cinema ticket.
The full price of a cinema ticket is EUR 13.70.
Based on age, the price is determined:
Younger than 5: free;
Between 5 and 12: half price;
Between 13 and 54: full price;
55+: free

MY codes:
C#:
//declaration variables
            const double cdblFullPriceTicket = 13.70;
            double dblEndPriceTicket;
            int int Age;

            dblEndPriceTicket = 0;

            //entry
            Console.Write("How old are you: ");
intAge = Convert.ToInt32(Console.Read()); ;




            if (intAge < 5)
            {

                //output
                Console.WriteLine();
                Console.Write("your cinema ticket is free.");
            }
            else if (intAge >= 5 && intAge<= 12)
            {
                //calculation
dblEndPriceTicket = cdblFullPriceTicket / 2;

                //output
                Console.WriteLine();
                Console.Write("you must pay " + Math.Round(dblEindPriceTicket, 2).ToString() + "EUR.");
            }
            else if (intAge >= 13 && intAge <= 54)
            {
                //calculation
                dblEndPriceTicket = cdblFullPriceTicket;

                //export
                Console.WriteLine();
                Console.Write("you must pay " + Math.Round(dblEindPriceTicket, 2).ToString() + "EUR.");
            }
            else if (intAge >= 55)
            {

                //output
                Console.WriteLine();
                Console.Write("your cinema ticket is free.");
            }
            else
            {
                Console.WriteLine();
                Console.Write("you don't enter any data");
            }


            Console.ReadKey();

I would put < 5 and >55 on one line. Also neater to round and calculate both ticket prices at the top.
 
Back
Top Bottom