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

Program to calculate pie, This problem familiarizes you with using random n...

This problem familiarizes you with using random numbers in C++. The program is to compute a good approximation of p using a simulation method called "Monte Carlo". The following fi

Explain the relationship between an array and pointers, Relationship betwee...

Relationship between an Array and Pointers. Consider the following. int arr[] = {0,1,2,3,4,5,6,7,8,9}; If we write arr , it is considered as the address of the first elem

Roman code python help , In general, Roman numerals can be converted mathem...

In general, Roman numerals can be converted mathematically by simply assigning a numerical value to each letter, according to the chart below, and calculating a total: M=1000 | D=5

Padovan string, #questio#A Padovan string P(n) for a natural number n is de...

#questio#A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concatenation. For a string

Solve system of linear equations-gaussian elimination , Write a C function ...

Write a C function to solve the system of linear equations A x = y where A is an N by N matrix in the format of pointer-to-pointers and y is a vector in the format of a pointer. Th

After p = new fred[n], After p = new Fred[n], how does the compiler know ab...

After p = new Fred[n], how does the compiler know about n objects to be destructed throughout delete[] p? A:  The run-time system hold the number of objects, n, somewhere where

Record of student and calculating marks using ctotal, reocord of a student ...

reocord of a student and a function ctotal to calculate the marks of any three subject by using ctotal() function

Assignment, Design a black box suit for function whether a character or st...

Design a black box suit for function whether a character or string up to 25 characters

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