Answer to Question #216367 in C# for Luyas

Question #216367

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

Younger than 2 2 - 12

13 or more

Ticket price

R 50 R 100 R 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-12T07:43:14-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace Q216367
{
    class Program
    {




        static void Main(string[] args)
        {
            double totalAmount = 0.0;
            int numberFamilyMembers = 0;
            //prompt the user for the number of family members who will be travelling on the bus. 
            Console.Write("Enter the number of family members who will be travelling on the bus: ");
            int.TryParse(Console.ReadLine(), out numberFamilyMembers);
            //For each travelling member the age must be entered, and the price determined and displayed.
            for (int i = 0; i < numberFamilyMembers; i++)
            {
                Console.Write("Enter the member the age {0}: ", (i + 1));
                int age = 0;
                int.TryParse(Console.ReadLine(), out age);
                //Younger than 2 R 50
                double price = 50;
                //2 - 12 R 100 
                if (age >= 2 && age <= 12)
                {
                    price = 100;
                }
                //13 or more R 180
                if (age >= 13)
                {
                    price = 180;
                }
                Console.WriteLine("The price is R {0}\n", price);
                totalAmount += price;
            }
            Console.WriteLine("The total amount a family needs to pay for bus tickets: R {0}", totalAmount);


            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