Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that operates a currency conversion between US Dollar (USD) and

ID: 3703252 • Letter: W

Question

Write a program that operates a currency conversion between US Dollar (USD) and EURO (EUR).

1) Immediately after execution, the program asks the user to insert the exchange rate from EURO to USD (e.g. 1 EUR=1.27 USD).

2) Then, the program asks the user to select which currency conversion is desired.

3) Then, the program converts and displays (in a tabular form) the first ten amounts (1-10 USD or 1-10 EUR) into the destination currency, using the appropriate exchange rate (EUR-> USD or USD->EUR).

4) The program loops over tasks 1, 2 and 3 to repeat the same procedure until the user entres an exchange rate of 0 (see example below). Hint: use a while loop that embraces tasks 1, 2 and 3, nad break out of this outer loop when the user enters 0.

Please write a program that will be compatible with the code editor Codeblocks

Explanation / Answer

The C code for this is as follows :


#include<stdio.h>
int main()
{
printf("Please enter the exchange rate from USD to EURO : ");
double xchgEURO;
scanf("%lf", &xchgEURO);// taking input from user , using double so as to get values after decimal too
int choice;
do{
printf("Enter 1 to convert from USD to EURO : ");
printf("Enter 2 to convert from EURO to USD : ");
printf("Enter 0 to exit : ");
scanf("%d", &choice); // taking input of choice from user
if(choice == 1)
{
int i;
for(int i = 1; i <= 10; i++)
{
double euro = (double)i * xchgEURO; // calculating the exchange amount
printf("%d USD to EURO is %lf : ", i, euro );
}
}
else if(choice == 2)
{
int i;
double xchgUSD = 1.0 / xchgEURO;
for(int i = 1; i <= 10; i++)
{
double usd = (double)i * xchgUSD; // calculating the exchange amount
printf("%d EURO to USD is %lf : ", i, usd);
}
}
else if(choice != 0)
{
printf("Invalid option, try again "); // if the user enter anything other than specified
}
else if(choice == 0)
{
printf("Exited successfully ");
}
}while(choice != 0); // to run the loop till 0 is not pressed
return 0;
}

The input/output is as follows :

Please enter the exchange rate from USD to EURO :
1.27
Enter 1 to convert from USD to EURO :
Enter 2 to convert from EURO to USD :
Enter 0 to exit :
1
1 USD to EURO is 1.270000 :
2 USD to EURO is 2.540000 :
3 USD to EURO is 3.810000 :
4 USD to EURO is 5.080000 :
5 USD to EURO is 6.350000 :
6 USD to EURO is 7.620000 :
7 USD to EURO is 8.890000 :
8 USD to EURO is 10.160000 :
9 USD to EURO is 11.430000 :
10 USD to EURO is 12.700000 :
Enter 1 to convert from USD to EURO :
Enter 2 to convert from EURO to USD :
Enter 0 to exit :
2
1 EURO to USD is 0.787402 :
2 EURO to USD is 1.574803 :
3 EURO to USD is 2.362205 :
4 EURO to USD is 3.149606 :
5 EURO to USD is 3.937008 :
6 EURO to USD is 4.724409 :
7 EURO to USD is 5.511811 :
8 EURO to USD is 6.299213 :
9 EURO to USD is 7.086614 :
10 EURO to USD is 7.874016 :
Enter 1 to convert from USD to EURO :
Enter 2 to convert from EURO to USD :
Enter 0 to exit :
3
Invalid option, try again
Enter 1 to convert from USD to EURO :
Enter 2 to convert from EURO to USD :
Enter 0 to exit :
0
Exited successfully

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote