Write a function to calculate the exchange rate, C/C++ Programming

Assignment Help:

Write a function to calculate the exchange rate of pounds to dollars 

Answer

      Td = 2xTp
 
The parameter passed over is the number of pounds and returned the value in dollars

    float  convert (float x )
    { 
      float  y ;
/*A function which converts pounds   measure X to a dollars measure*/
    /*The parameter x is real and a real value y  is  returned*/
       y = 2.0  * x;
       return (y);
    }
The program which calls the function would be
    include
    include
    include
    include
    include
    void  main()
    {
    char prompt;
     float  a, b;
    printf("please enter in your value in pounds  \n\r");
     scanf("%f",&a);
     b= convert(a);
     printf("The value in dollars  is %5.3f \n\r",b);
     b= convert(3.0);
     printf("The value in dollars of 3 pounds   is %5.3f \n\r",b);   
    printf("Press any key to exit \n\r");
    scanf("\n%c",&prompt);
    }

 Here the program requests the value of a in pounds, then executes function 'Convert'. This causes the program to go to the function statement, pass the variable a, to it and the output is passed back to the program. The output is then assigned to variable b and printed out. It is possible to pass a value over instead of a variable. The only amendment we have to make is to add the prototype to the program i.e.

    float convert (float);
 
This describes the type of variables passed to and from the function. Therefore the complete program and function is shown below 
 
    include
    include
    include
    include
    include
    float  convert (float);
    void main()
    {
    char prompt;
     float  a, b;
    printf("please enter in your in pounds \n\r");
     scanf("%f",&a);
     b= convert(a);
     printf("The value in dollars is %5.3f \n\r",b);
     b= convert(3.0);
     printf("The value in dollars  of 3 pounds is %5.3f \n\r",b);   
                        printf("Press any key to exit \n\r");
    scanf("\n%c",&prompt);
    }
 
    float  convert (float x )
    { 
      float  y ;
/*A function which converts pounds   measure X to a dollars measure*/
    /*The parameter x is real and a real value y  is  returned*/
     
        y = 2.0  * x;
       return (y);
    }


Related Discussions:- Write a function to calculate the exchange rate

Coding, A palindrome is a string that reads the same from both the ends. Gi...

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

External iterator and an internal iterator, What is the difference between ...

What is the difference between an external iterator and an internal iterator? Ans) An internal iterator is executed with member functions of the class that has items to step th

Pointer to function, Pointer to function: int mul(int a, int b, int c) ...

Pointer to function: int mul(int a, int b, int c) {   return a*b*c; } void main() {   int (*function_pointer)(int, int, int);   function_pointer = &mul;

Decompression of files compressed with LZW, The files are meteorological ra...

The files are meteorological radar data whose decompression is badly needed for relative study. Please contact Kathy Lee (Email: ; Cell phone: 0086 15701799056) or Mr. Zhu (Email:

Define scope rules of c program - computer programming, Define Scope Rules ...

Define Scope Rules of C program - Computer Programming? The fundamental rule of scope is that identifiers are accessible only within the block in which they are declared and th

Stack and queues, Using Figure 10.2 as a model, illustrate the result of ea...

Using Figure 10.2 as a model, illustrate the result of each operation in the sequence ENQUEUE.Q; 4/, ENQUEUE.Q; 1/, ENQUEUE.Q; 3/, DEQUEUE.Q/, ENQUEUE.Q; 8/, and DEQUEUE.Q/ on an i

Bus Connection, how to explain working of bus connection

how to explain working of bus connection

Arrays and pointers, i have an array of structs, and am trying to make a po...

i have an array of structs, and am trying to make a pointer that can point to a certain struct within the array

Last ant on rod, There are ''n'' ants on a ''n+1'' length rod. The ants are...

There are ''n'' ants on a ''n+1'' length rod. The ants are numbered from 1 to n and are initially placed at positions starting from position 1 till position n. They are moving eith

#title.Thick line, #questio c++ program for drawing thick line

#questio c++ program for drawing thick line

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd