Академический Документы
Профессиональный Документы
Культура Документы
In this lab, I broke the program down into four basic parts and each of them handles
a specific task. I first started it by writing a function that takes x-component, ycomponent, z-component and calculate the magnitude using Pythagorass theorem
Equation 1:
//convert between US dollar and Vietnam dong if input letters are 'U' and 'V', or 'u' and
'v'
if (((fromCur == 'U') && (toCur == 'V')) || ((fromCur == 'u') && (toCur == 'v'))){
return inVal*US_VND;
} else if ((fromCur == 'V') && (toCur == 'U')){
return inVal*(1.0/US_VND);
}
//convert betweem japanese yen and vietnam dong if input letters are 'Y' and 'V', or 'y'
and 'v'
if (((fromCur == 'Y') && (toCur == 'V')) || ((fromCur == 'y') && (toCur == 'v'))){
return inVal*YEN_VND;
} else if ((fromCur == 'V') && (toCur == 'Y')){
return inVal*(1.0/YEN_VND);
}
return 0;
}
int main()
{
//These line display the message and currencies to the user
printf("Welcome to the Currency Converter\n");
printf(" $$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $$\n\n");
printf("List of currencies:\n");
// Table of the 3 currencies and their code
printf("Currency\t\t\t Code\n");
printf("1. US dollar\t\t U\n");
printf("2. Japanese Yen\t\t Y\n");
printf("3. Vietnam Dong\t\t V\n\n");
//The while loop allows the user to stop the program if enter 'q', otherwise, the
program
//will continue taking inputs.
while (fromCur != 'q') {
//Ask the user for the inputs
printf("Enter the value in the format: current currency code,new currency
code,value\n");
printf("Or enter q to quit\n");
scanf("%c,%c,%lf", &fromCur, &toCur, &inVal);
//Outputs the result and round to the hundredth
printf("%.2lf %c equals %.2lf %c\n\n", inVal, fromCur, convertCur(inVal, fromCur,
toCur), toCur);
}
//Display the message if the condidtion of the while loop is false
printf("\nGood Bye.\n");
return 0;
}