Breaking Down Bolivars: Currency Calculation in C#
C# Currency Breakdown Calculator
This program is designed to perform calculations with currency, specifically Bolivars. It offers two main functionalities:
- Breaking down a given amount into different denominations of bills and coins.
- Calculating the total value based on the quantity of each denomination entered.
Authors:
- Luis Salazar (CI: 18,399,892)
- Santiago Reyes (CI: 18,399,892)
Program Structure
The program utilizes a while
loop to continuously prompt the user for input until the exit option (“X”) is selected. Inside the loop, a menu is displayed with the following options:
- Enter an amount in Bolivars to break down into denominations.
- Enter the quantity of each denomination to get the total in Bolivars.
- Exit (X).
A switch
statement handles the user’s choice, executing the corresponding code block.
Option 1: Breaking Down an Amount
When the user selects option 1, the program prompts them to enter an amount. It then calculates the number of each denomination (bills of 100, 50, 20, 10, 5, and 2 Bolivars, and coins of 1 and 0.50 Bolivars) required to represent that amount.
Example:
Console.WriteLine("Please, Enter Amount");
amount = decimal.Parse(Console.ReadLine());
b100 = (int)amount / 100;
b50 = (int)(amount - (b100 * 100)) / 50;
// ... (calculations for other denominations)
The results are then displayed to the user:
Console.WriteLine("The Number of 100Bs bills is: {0}", b100.ToString());
Console.WriteLine("The Number of 50Bs bills is: {0}", b50.ToString());
// ... (output for other denominations)
Option 2: Calculating Total from Denominations
If the user chooses option 2, the program asks for the quantity of each denomination. It’s crucial to enter a value for every denomination, using zero (0) for those not present.
Example:
Console.WriteLine("Enter the number of 100Bs bills");
B100 = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the number of 50Bs bills");
B50 = int.Parse(Console.ReadLine());
// ... (input for other denominations)
The total amount is then calculated:
total = (B100 * 100) + (B50 * 50) + (B20 * 20) + (B10 * 10) + (B5 * 5) + (B2 * 2) + (MO1 * 1) + (MO50 * 0.50) + (MO25 * 0.25) + (MO125 * 0.125) + (MO5 * 0.05) + (M1 * 0.01);
Finally, the total is displayed:
Console.WriteLine("The amount in Bolivars is: {0}", total.ToString());
Exiting the Program
Choosing “X” from the main menu terminates the program.