Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Beginner at C, float variables outputting as "0.00" after arithmetic.

Tags:

c

I am new to C and I am having trouble with a basic program that converts dollars to euros. When I print the final output both the dollar and euro amount is "0.00". Here is my code:

#include<stdio.h>

main()

{
    float usd = 0.00;
    float euro = 0.00;
    const float conversion = 0.75;

    printf("Please enter the amount of USD you want to convert to Euros: ");
    scanf("%f", &usd);

    euro = (usd * conversion);
    printf("\n%.2f USD equals %.2f Euros.", &usd, &euro);


    getch();
    return 0;
}

Thanks in advance

like image 435
Petefic Avatar asked Jan 29 '26 05:01

Petefic


2 Answers

Change the printf line to this:

printf("\n%.2f USD equals %.2f Euros.", usd, euro);

You are passing the addresses of usd and euro rather than the values themselves.

like image 197
Mysticial Avatar answered Jan 30 '26 21:01

Mysticial


printf("\n%.2f USD equals %.2f Euros.", usd, euro);
like image 26
Foo Bah Avatar answered Jan 30 '26 20:01

Foo Bah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!