added rounding

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