/*
Génesis M Ojeda Rosa
COMP 3800
lenguaje COMP
Conversión de dólares a pesos colombianos, yen y euros.cSwitch
*/
// Import library
#include <stdio.h>
// Define constants
#define COLOMBIAN_DOLLARS 4215
#define EUROS 0.93
#define YEN 143.86
int main() {
double us_dollars, colombian_dollars, euros, yen;
int choice, control = 1;
// while True
while (control == 1) {
// Display the menu of conversion
printf("Currency Converter Menu:\n");
printf("1. Convert to Colombian Pesos\n");
printf("2. Convert to Euros\n");
printf("3. Convert to Yen\n");
printf("4. Exit program\n");
printf("Enter your choice: ");
scanf("%d", &choice);
if (choice < 1 || choice > 4) {
printf("\nPlease enter a choice from the menu.\n");
continue; // Continues loop if the choice is invalid.
} else if (choice == 4) {
control = 0;
} else {
// Ask for the amount
printf("Enter USD amount to convert: ");
scanf("%lf", &us_dollars);
// Perform the conversion based on the choice
switch(choice) {
case 1:
colombian_dollars = COLOMBIAN_DOLLARS * us_dollars;
printf("%.2f USD is %.2f Colombian Pesos.\n", us_dollars, colombian_dollars);
break;
case 2:
euros = EUROS * us_dollars;
printf("%.2f USD is %.2f Euros.\n", us_dollars, euros);
break;
case 3:
yen = YEN * us_dollars;
printf("%.2f USD is %.2f Yen.\n", us_dollars, yen);
break;
}
// Ask if the user wants to continue
printf("\nDo you wish to continue? (0 = no, 1 = yes)\n");
scanf("%d", &control);
while (control != 0 && control != 1) {
printf("Please, enter 0 for 'no' and 1 for 'yes': ");
scanf("%d", &control);
}
}
}
return 0;
}