Thread: The current exchange rate

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    4

    The current exchange rate

    hi all


    i have an error message in my code ..
    the question is :
    write a C program that asks for input as US dollars and uses the function to display the output as GBP sterling. The current exchange rate is 1 GBP to 1.5207 USD.

    if anyone could help me with it


    my code :

    Code:
    #include <stdio.h>
             
    int main(void)
    {
     int input = 0;
       do
       {
          printf( "\nPlease enter a dollar amount to exchange to GBP: " );
          scanf( "%d", &input );
    
          if ( input > 0 )
          
                   printf ("Great Britian: = "%f"/ 1.5207\n",GBP);
          
                } while ( input< 20 );
                
             return 0;
    }
    i asked to do it with this line but i coudn't

    Code:
      double gbp_to_usd( double );

    thanks

  2. #2
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    You have to create a function and call it:
    Code:
    double gbp_to_usd( double in) {
       // Your code here
    }
    Then you have to call it:
    Code:
                   printf ("Great Britian: = %f\n",gbp_to_usd(input));
    but I think you have something backwards. You are converting from usd to gbp, but the function is called gbp_to_usd?
    EDIT: Also check your printf statement. It has closing " when it shouldn't. Do you mean \"

  3. #3
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195
    In your post, you try and do it using the line of code: double gbp_to_usd( double );

    Have you written that function?

    You haven't defined the variable "GBP", from what I can tell, that is meaningless at the moment.

    edit: lol. I was too slow :P

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4
    well i am trying to do it as u said but still having errors

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    4
    Quote Originally Posted by Swarvy View Post
    In your post, you try and do it using the line of code: double gbp_to_usd( double );

    Have you written that function?

    You haven't defined the variable "GBP", from what I can tell, that is meaningless at the moment.

    edit: lol. I was too slow :P

    No i asked to do it with that function ..

  6. #6
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    Well what have you tried. This isn't a difficult problem. Post what you have tried for converting. We don't do work here for others. We are here to help and give advice.

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    4
    this is what i have done so far and it works


    Code:
     double gbp_to_usd( double );
    
    int main( void )
    {
       double usd = 0.0;
       scanf( "%lf", &usd );
       printf( "%.2lf usd is equivalent to %.2lf gbp", usd, gbp_to_usd( usd ) );
    }
    
    double gbp_to_usd( double usd )
    {
       return ( usd * 1.5207 );
    }

    thanks

  8. #8
    Registered User
    Join Date
    Apr 2009
    Posts
    41
    Quote Originally Posted by BB.BB View Post
    this is what i have done so far and it works


    Code:
     double gbp_to_usd( double );
    
    int main( void )
    {
       double usd = 0.0;
       scanf( "%lf", &usd );
       printf( "%.2lf usd is equivalent to %.2lf gbp", usd, gbp_to_usd( usd ) );
    }
    
    double gbp_to_usd( double usd )
    {
       return ( usd * 1.5207 );
    }

    thanks
    You forgot the part of the code where if %.2lf goes past the hundreth decimal pace it sends the remainder (.00XXXXX) to your personal bank account.

  9. #9
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Quote Originally Posted by BB.BB View Post
    this is what i have done so far and it works...
    I don't think so. Your calculation is still backwards.

    1 British Pound Sterling = 1.5207 US Dollar (you said)

    To convert US to pound, you'd do US$ / 1.5207.

  10. #10
    Registered User
    Join Date
    Apr 2009
    Location
    Russia
    Posts
    116
    same solution with functions

  11. #11
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    431
    Quote Originally Posted by strickyc View Post
    You forgot the part of the code where if %.2lf goes past the hundreth decimal pace it sends the remainder (.00XXXXX) to your personal bank account.
    *applause*
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Immediate programming help! Please!
    By xMEGANx in forum C++ Programming
    Replies: 6
    Last Post: 02-20-2008, 12:52 PM
  2. Problem with simple case statements
    By shoobsie in forum C Programming
    Replies: 2
    Last Post: 05-08-2006, 08:39 AM
  3. Newbie Help: Currency Converter
    By Ashfury in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 01:21 PM
  4. compiler build error
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2003, 10:16 AM
  5. linked list recursive function spaghetti
    By ... in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2003, 02:53 PM