Photo AI

A group of people have a meal in a restaurant - AQA - GCSE Computer Science - Question 15 - 2023 - Paper 1

Question icon

Question 15

A-group-of-people-have-a-meal-in-a-restaurant-AQA-GCSE Computer Science-Question 15-2023-Paper 1.png

A group of people have a meal in a restaurant. Instead of one person paying for the whole meal, each person will pay for what they eat. Write a C# program that asks... show full transcript

Worked Solution & Example Answer:A group of people have a meal in a restaurant - AQA - GCSE Computer Science - Question 15 - 2023 - Paper 1

Step 1

get the user to enter the total amount of the bill

96%

114 rated

Answer

// Declare a variable for the total amount
Console.Write("Enter the total amount of the bill: ");
double totalAmount = Convert.ToDouble(Console.ReadLine());

Step 2

get a person to enter how much they are paying towards the bill

99%

104 rated

Answer

double amountPaid;
double amountLeft = totalAmount;

while (amountLeft > 0)
{
    Console.Write("Enter amount paid: ");
    amountPaid = Convert.ToDouble(Console.ReadLine());
    amountLeft -= amountPaid;
    
    if (amountLeft > 0)
    {
        Console.WriteLine($"Amount left to pay: {amountLeft}");
    }
    else if (amountLeft == 0)
    {
        Console.WriteLine("Bill paid");
    }
    else
    {
        Console.WriteLine($"Tip is: {Math.Abs(amountLeft)}");
    }
}

Join the GCSE students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;