added rounding
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user