A group of people have a meal in a restaurant - AQA - GCSE Computer Science - Question 15 - 2023 - Paper 1
Question 15
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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
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
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
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)}");
}
}