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

How the operations are performed in a single linked list, Question: (a)...

Question: (a) Explain a linked list. (b) Describe the three different types of linked list with the help of diagrams. (c) Give two advantages and two disadvantages

Algorithm, Write algorithms to implement the insertion and deletion operati...

Write algorithms to implement the insertion and deletion operations.

#CompilerRelated, #C Why don''t online compilers support the header file?...

#C Why don''t online compilers support the header file? What can I do to resolve this? PS. I have tried , does''nt work either. Thannk in advance.

What is the difference between structure and class, What is the difference ...

What is the difference between structure and class? - Members of structures are public while those of a class are private. - Classes provide data hiding while structures don

.Change to palindrome, A palindrome is a string that reads the same from bo...

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

Blanche has a fashion design company called BLB_Best_Clothin, Blanche has a...

Blanche has a fashion design company called BLB_Best_Clothing Pty. That she has just opened recently

Main-elipse -vector-arrays in cpp , Unlike C++, other programming languages...

Unlike C++, other programming languages have associative arrays that allow array indices to be strings instead of just integers. You are to create a template class, SVector, that i

Program for greatest common divisor – c++ program, Greatest Common Divisor ...

Greatest Common Divisor (GCD) - The greatest common divisor (GCD) of two integers is the largest integer that will evenly divide both integers. The GCD algorithm involves intege

Area under the curve, Write a c++ program to find the area under the curve ...

Write a c++ program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points c

Command-line arguments, Command-line arguments are passed into programs usi...

Command-line arguments are passed into programs using the arguments of main(). Here's a quick example, for a program called by typing "progname file.txt 1 2.7": #include #incl

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