Hi there,
I am trying to make a program to convert currency.
I am stuck in a function call, more specifically this one part below. Instead of getting the the amount of euros I get for exchanging USD, I get a very long number which does not make sense. As I don't get any warning or error and all compiles fine I don't know what I am doing wrong... Can anyone help? / thnx, Bluetxxth.
Code:
#include <stdio.h>
#include <stdlib.h>
#define RATE 1.3 // the exchange rate
/*Function takes input from the user (USD and it converts them to EUR
* Param: doble - usd integer which holds the ammount of USD
* Return: double - change in Euros
*/
double usd_to_eur(double usd) {
double rate = 1 / RATE; // euro conversion rate
double change;
printf("Enter currency in USD: ");
scanf("%f", &usd);
change = usd * rate;
return change;
}
int main(void) {
double chng, // variable which contains the return value of the function usd_to_eur()
eur; //variable for the actual parameter int the function call which corresponds to the formal parameter
chng = usd_to_eur(eur);
printf("Exchange is: %.2f", chng); // prints the result of the currency conversion
return (0);
}