Program to convert rupee to dollars and dinars and vice versa |C Program|

Introduction

     Currency conversion is a fundamental aspect of financial transactions, and in the world of programming, creating a currency converter can be a valuable skill. In this blog post, we explore a C program that facilitates straightforward currency conversions between Rupees, Dollars, and Dinars. The program allows users to convert amounts seamlessly based on their chosen currency code.  

Code

    
     
        // Program to convert rupee to dollars and dinars and vice versa 
        #include<stdio.h>
        #include<conio.h>
        void main()
        {
        float rs,dl,dn;
        int code;
        clrscr();
        printf("enter your code:\n 1.for rupees to doller\n 2.for doller rupees\n 3.for rupees to dinar\n 4.for dinar to rupees");
        scanf("%d",&code);
        if(code==1)
        {
        printf("enter your amount(rs):");
        scanf("%f",&rs);
        dl=rs/65.21;
        printf("you have doller:%f",dl);
        }
        else if(code==2)
        {
        printf("enter the amount in doller:");
        scanf("%f",&dl);
        rs=dl*65.21;
        printf("you has rupees:%f",rs);
        }
        else if(code==3)
        {
        printf("enter your amount in rupees:");
        scanf("%f",&rs);
        dn=rs/210;
        printf("you have dinar:%f",dn);
        }
        else if (code==4)
        {
        printf("enter youth amount in dinar:");
        scanf("%f",&dn);
        rs=dn*210;
        printf("you have rupees%f",rs);
        }
        else
        printf("invalid convertion");
        getch();
        }
       
     


Output

    
        // Output
    enter your code:
    1.for rupees to doller
    2.for doller rupees
    3.for rupees to dinar
    4.for dinar to rupees
    1
    enter your amount(rs):100
    you have doller:1.533507
       




Explanation

1. Header Files:
The program includes the standard input/output header <stdio.h> and the console I/O header <conio.h>.
2. Main Function:
The main function initiates the program.
Variables rs, dl, and dn are used to store amounts in Rupees, Dollars, and Dinars, respectively.
Users are prompted to enter a code for the desired currency conversion.
3 .Currency Conversion:
The program uses a series of if-else statements to determine the chosen conversion.
Depending on the code entered by the user, the program calculates and displays the converted amount.
4. User Interaction:
Users are guided through the conversion process with clear prompts and input requests.


Conclusion

     This C program provides a user-friendly currency conversion tool, allowing users to effortlessly switch between Rupees, Dollars, and Dinars. Understanding the logic behind such conversions is valuable in financial applications and can serve as a foundation for more complex programs. Experiment with the code, try different conversion scenarios, and enhance your programming skills in the realm of currency handling. Happy coding!

Post a Comment

0 Comments