0% found this document useful (0 votes)
20 views3 pages

Equation 1:: Determine The Magnitude

The document describes a program that calculates currency conversions between US dollars, Japanese yen, and Vietnamese dong. The program contains a function that takes the input currency code, output currency code, and value. It uses if/else statements to check the currency codes and call the appropriate conversion rate. The main function gets input from the user, calls the conversion function, and displays the output rounded to two decimal places. It uses a while loop to allow multiple conversions and exits when the user enters 'q'.

Uploaded by

jiderjustin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Equation 1:: Determine The Magnitude

The document describes a program that calculates currency conversions between US dollars, Japanese yen, and Vietnamese dong. The program contains a function that takes the input currency code, output currency code, and value. It uses if/else statements to check the currency codes and call the appropriate conversion rate. The main function gets input from the user, calls the conversion function, and displays the output rounded to two decimal places. It uses a while loop to allow multiple conversions and exits when the user enters 'q'.

Uploaded by

jiderjustin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Determine the magnitude

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:

/define conversion factors


#define US_YEN 102.31 //from US dollar to Japanese yen
#define US_VND 21105.00 //from US dollar to Vietnam dong
#define YEN_VND 206.28 //from Japanese to Vietnam dong
// Initialize varibles
double inVal = 0; //initialize the user input variable
double outVal = 0; //initialize the user output variable
char fromCur, toCur; //variables that store code of currency
// The function takes three arguments and calculate the output when the letter codes
match the conditions
double convertCur(double inVal, char fromCur, char toCur){
//convert between US dollar and Japanese yen if input letters are 'U' and 'Y', or 'u' and
'y'
//there is an or operator so the user can enter either Upppercase or lowercase
if (((fromCur == 'U') && (toCur == 'Y')) || ((fromCur == 'u') && (toCur == 'y'))){
return inVal*US_YEN;
} else if ((fromCur == 'Y') && (toCur == 'U')){
return inVal*(1.0/US_YEN);
}

//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;
}

You might also like