In this tutorial, we will write a C program for currency conversion. Before that, you may go through the following topic in C.
Explanation: In this program, there is a use of switch statements in C. The program gives the user choice for the conversion. For this example, we have taken four currencies those are Rupee, Dollar, Pound and Euro.
There are four cases for each currency conversion. You can modify the value of a currency with the actual current value.
Currency Conversion Program in C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | #include <stdio.h> int main() { float amount; float rupee, dollar, pound, euro; int choice; printf("Following are the Choices:"); printf("\nEnter 1: Ruppe"); printf("\nEnter 2: Dollar"); printf("\nEnter 3: Pound"); printf("\nEnter 4: Euro"); printf("\nEnter your choice: "); scanf("%d", &choice); printf("Enter the amount you want to convert?\n"); scanf("%f", &amount); switch (choice) { case 1: // Ruppe Conversion dollar = amount / 70; printf("%.2f Rupee = %.2f dollar", amount, dollar); pound = amount / 88; printf("\n%.2f Rupee = %.2f pound", amount, pound); euro = amount / 80; printf("\n%.2f Rupee = %.2f euro", amount, euro); break; case 2: // Dollar Conversion rupee = amount * 70; printf("\n%.2f Dollar = %.2f rupee", amount, rupee); pound = amount *0.78; printf("\n%.2f Dollar = %.2f pound", amount, pound); euro = amount *0.87; printf("\n%.2f Dollar = %.2f euro", amount, euro); break; case 3: // Pound Conversion rupee = amount * 88; printf("\n%.2f Pound = %.2f rupee", amount, rupee); dollar = amount *1.26; printf("\n%.2f Pound = %.2f dollar", amount, dollar); euro = amount *1.10; printf("\n%.2f Pound = %.2f euro", amount, euro); break; case 4: // Euro Conversion rupee = amount * 80; printf("\n%.2f Euro = %.2f rupee", amount, rupee); dollar = amount *1.14; printf("\n%.2f Euro = %.2f dollar", amount, dollar); pound = amount *0.90; printf("\n.2%f Euro = %.2f pound", amount, pound); break; //Default case default: printf("\nInvalid Input"); } return 0; } |
Output:
Following are the Choices:
Enter 1: Ruppe
Enter 2: Dollar
Enter 3: Pound
Enter 4: Euro
Enter your choice: 2
Enter the amount you want to convert?
7
7.00 Dollar = 490.00 rupee
7.00 Dollar = 5.46 pound
7.00 Dollar = 6.09 euro
There is a use of “%.2f
” which means only two digits after the decimal value will be displayed.