Write a program that prompts the user to enter the exchange rate from currency i
ID: 3669427 • Letter: W
Question
Write a program that prompts the user to enter the exchange rate from currency in U.S. dollars to Chinese RMB (in other words, how many RMB are equivalent to 1 U.S. dollar?). Prompt the user to enter 0 to convert from U.S. dollars to Chinese RMB and 1 to convert from Chinese RMB to U.S. dollars. Prompt the user to enter the amount in U.S. dollars or Chinese RMB to convert it to Chinese RMB or U.S. dollars, respectively.
Here is a sample run:
Enter the exchange rate from dollars to RMB: 6.81
Enter 0 to convert dollars to RMB and 1 vice versa: 0
Enter the dollar amount: 100
$100.0 is 681.0 yuan
Explanation / Answer
#include <stdio.h>
int main()
{
double exchange;
double dollar,yuan;
int choice;
printf("Enter the exchange rate from dollars to RMB: ");
scanf("%lf",&exchange);
printf("Enter 0 to convert dollars to RMB and 1 vice versa: ");
scanf("%d",&choice);
if(choice==0)
{
printf("Enter the dollar amount: ");
scanf("%lf",&dollar);
yuan = dollar*exchange;
printf("$%0.1lf is %0.1lf yuan ", dollar,yuan);
}else{
printf("Enter the yuan amount: ");
scanf("%lf",&yuan);
dollar = yuan/exchange;
printf("%0.1lf yuan is $%0.1lf ", yuan, dollar);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.