Write a C# program that will create the following:
IT0083 – Game Design 1 Page 4 of 4
a. A program that will ask an amount from the user.
b. The program will count how many one thousand, five hundred, two hundred, one
hundred, fifty, twenty, ten, five, one, fifty cents, twenty-five cents, ten cents, and five
cents Philippine peso bills.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Certainly! Below is a simple C# program that asks the user for an amount in Philippine Pesos and then calculates how many notes and coins of each denomination are needed to make up that amount. This program includes denominations for 1000, 500, 200, 100, 50, 20, 10, 5, and 1 peso, as well as 50, 25, 10, and 5 centavos.
csharp
using System;
class CurrencyCalculator
{
static void Main()
{
// Prompt the user for an amount
Console.WriteLine("Please enter an amount in Philippine Pesos:");
double amount = Convert.ToDouble(Console.ReadLine());
// Define the denominations in an array
int[] pesoDenominations = { 1000, 500, 200, 100, 50, 20, 10, 5, 1 };
double[] centavoDenominations = { 0.50, 0.25, 0.10, 0.05 };
// Initialize variables to hold count of each denomination
int[] pesoCounts = new int[pesoDenominations.Length];
int[] centavoCounts = new int[centavoDenominations.Length];
// Calculate the number of peso bills
for (int i = 0; i < pesoDenominations.Length; i++)
{
pesoCounts[i] = (int)(amount / pesoDenominations[i]);
amount %= pesoDenominations[i];
}
// Calculate the number of centavo coins
for (int i = 0; i < centavoDenominations.Length; i++)
{
centavoCounts[i] = (int)(amount / centavoDenominations[i]);
amount = Math.Round(amount % centavoDenominations[i], 2);
}
// Output the results
Console.WriteLine("\nTo make up the amount, you will need:");
for (int i = 0; i < pesoDenominations.Length; i++)
{
if (pesoCounts[i] > 0)
{
Console.WriteLine($"{pesoCounts[i]} x Php {pesoDenominations[i]} bill(s)");
}
}
for (int i = 0; i < centavoDenominations.Length; i++)
{
if (centavoCounts[i] > 0)
{
Console.WriteLine($"{centavoCounts[i]} x {centavoDenominations[i] * 100} centavo coin(s)");
}
}
Console.WriteLine("\nPress any key to exit.");
Console.ReadKey();
}
}
How the Program Works:
Collecting Input: The program starts by prompting the user to enter an amount in pesos.
Computing Notes and Coins: It uses loops to determine how many of each denomination are needed, starting from the largest to the smallest currency unit.
Displaying Results: The program then outputs the number of each type of note and coin required.
Exiting: The user is prompted to press any key to exit once they review the breakdown.
This program rounds down denominations for pesos and performs a rounding method for centavos to avoid floating-point arithmetic issues typical with financial calculations.
To compile and run this program, use a C# compiler, or run it within an IDE or a tool that supports C# execution. Modify the array of denominations if there are changes in currency usage or to adapt to different monetary systems.