Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

finding a word and preforming a math function

piczimpiczim Posts: 11Member
I am wanting to write a simple bit of code that converts a currency into US$

I have managed thus far to get it to ask which currency I want to convert now I am not sure where to go from here

[code]#include
#include
int main()
{
char n1[20];// rand
char n2[20];// pounds
char n3[20];// yen

puts("What currency do you want to convert to US$:
");
scanf("%s",n1,n2,n3);
printf("
");
printf("You want to convert %s to US$
",n1,n2,n3);
printf("
");

return(0);
}[/code]

Comments

  • WessichtWessicht Posts: 3Member
    Hi, Piczim. You might have better luck if you used floating point variables instead of strings. For example:

    [code]
    /* This program converts an input dollar amount to yen,
    using a sample exchange rate of 200.41. It is written for
    piczim. Author: Jose Luis Nunez. Public Domain: True*/

    #include
    #include

    #define RATE 200.41 //assuming exchange rate is 200.41

    float conv_yen(float dollars);

    int main(void){
    float dollars;
    float yen;

    printf("Enter Amount: ");
    scanf("%f", &dollars);

    yen = conv_yen(dollars);
    printf("
    $%6.2f = %8.2f yen
    ", dollars, yen);
    return 0;
    }

    float conv_yen(float dollars){
    return(dollars * RATE);
    }
    [/code]
    You can then operate on the variables directly, and add the dollar/yen signs in output. Hope this helps!
Sign In or Register to comment.