Answer to Question #216550 in C# for Melusi

Question #216550
Write a program that can be used to determine the total amount a family needs to pay for bus tickets. The
price for a bus ticket is linked to the age of the passenger, as indicated in the table below:

Age price
Younger than 2 $ 50
2 - 12 $100
13 or more $ 180

The program must prompt the user for the number of family members who will be travelling on the bus. For
each travelling member the age must be entered, and the price determined and displayed. When all family
members have been processed, the total amount due must be displayed. Monetary amounts must be
displayed with currency formatting. (You may assume that only valid ages will be entered)
1
Expert's answer
2021-07-12T17:17:31-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace Q216550
{
    class Program
    {




        static void Main(string[] args)
        {
            double amount = 0.0;
            int numberMembers = 0;
            Console.Write("Enter the number of family members: ");
            numberMembers = int.Parse(Console.ReadLine());
            for (int i = 0; i < numberMembers; i++){
                int age = -1;
                while (age < 0 || age > 150) {
                    Console.Write("Enter the age for the member {0}: ", (i + 1));
                    age = int.Parse(Console.ReadLine());
                }
                double ticketPrice = 0;
                if (age < 2)
                {
                    ticketPrice = 50;
                }
                if (age >= 2 && age <= 12)
                {
                    ticketPrice = 100;
                }
                if (age >= 13)
                {
                    ticketPrice = 180;
                }
                Console.WriteLine("A bus ticket price is ${0}\n", ticketPrice);
                amount += ticketPrice;
            }
            Console.WriteLine("\nThe total amount a family needs to pay for bus tickets: ${0}", amount);


            Console.ReadLine();
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS