added rounding
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
// variables
|
// variables
|
||||||
@@ -13,6 +14,12 @@ int main() {
|
|||||||
printf("\n1 EUR\n2 USD\n3 JPY\n\nPlease type in the target currency: ");
|
printf("\n1 EUR\n2 USD\n3 JPY\n\nPlease type in the target currency: ");
|
||||||
scanf("%i", &targetCurrency);
|
scanf("%i", &targetCurrency);
|
||||||
|
|
||||||
|
// check for valid input
|
||||||
|
if (currentCurrency < 1 || currentCurrency > 4 || targetCurrency < 1 || targetCurrency > 4) {
|
||||||
|
printf("Invalid currencies.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// calculating
|
// calculating
|
||||||
if (currentCurrency != targetCurrency) {
|
if (currentCurrency != targetCurrency) {
|
||||||
// converting to base currency
|
// converting to base currency
|
||||||
@@ -39,6 +46,9 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// rounding fun
|
||||||
|
amount = round((amount*100))/100;
|
||||||
|
|
||||||
// output
|
// output
|
||||||
printf("Amount in target currency is: %lf", amount);
|
printf("Amount in target currency is: %lf", amount);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user