Currency Converter In C++ - C++ Programming Tutorial
C++ Course / Miscellaneous / Currency Converter In C++

Currency Converter In C++

BLUF: Mastering Currency Converter In C++ is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Currency Converter In C++

C++ is renowned for its efficiency. Learn how Currency Converter In C++ enables low-level control and high-performance computing in the tutorial below.

Converting currencies poses a common challenge for individuals in their daily lives. As part of our routine tasks, we often encounter the need to convert currencies. Hence, developing a C++ application for currency conversion can serve as a valuable tool for this purpose.

If you are familiar with coding, you may have likely developed currency conversion applications using C, Python, Java, and various other programming languages.

If you're new to this, stay tuned and discover how to create a currency converter in C++.

Currency to Convert

We'll convert the dollars into British Pounds, French Francs, German Dutch Schillings, Japanese Yen, Indian Rupees, and French Francs. This program provides an ideal solution for the textbook query, which is also featured in multiple textbooks.

Prerequisites: Fundamental currency conversions, variables in the C++ programming language, and familiarity with Visual Studio.

Program Breakdown

Example

#include < iostream >
using namespace std ;
int main ( )

We are going to add the iostream library from C++ to our currency conversion program. A namespace serves as a declarative region that encapsulates the names of types, functions, variables, and more within its scope.

Example

float dollar ;

Here, a variable of type float named dollar has been initialized. Due to its quicker performance and more limited range compared to double type, float has traditionally been the choice when handling numerous floating-point values in the hundreds or millions.

Example

float bp = ( 1 / 1 . 487 ) ;
float frnc = ( 1 / 0 . 172 ) ;
float deutschmark = ( 1 / 0 . 584 ) ;
float yen = ( 1 / 0 . 00955 ) ;
float ind = ( 1 / 0 . 013 ) ;

In the provided snippet of pseudo code, we have initialized multiple float variables representing different currencies. For instance, 'bp' corresponds to British pounds with a basic conversion rate obtained by dividing 1 by 1.487. Similarly, 'frnc' represents French Francs, where dividing 1 by 0.172 yields the fundamental conversion rate. 'deutschmark' signifies German Dutch Schillings, and dividing 1 by 0.584 gives the essential conversion. 'yen' denotes Japanese Yen, with the basic conversion calculated by dividing 1 by 0.00955. Lastly, 'ind' stands for Indian Rupees, and dividing 1 by 0.013 provides the primary conversion value.

Example

cout << " Enter the Dollars for Conversion : \ n " ;
cin >> dollar ;

Here, this section indicates that users are prompted to input the dollar amount for conversion, which is then stored in a variable of type float named dollar.

Example

cout << " Indian Rupees : " << ind * dollar << endl ; 
cout << " British Pounds : " << bp * dollar << endl ;
cout << " French franc : " << frnc * dollar << endl ;
cout << " German Deutschmark : " << deutschmark * dollar << endl ;
cout << " Japanese Yen : " << yen * dollar << endl ;
return 0 ;

To calculate the converted currency value, we will multiply our floating-point variables' base conversion rates by the amount in dollars provided by the user. An illustration is provided below.

Program of Above Explanation

Example

#include < iostream >
using namespace std ; 
int main ( ) 
{
float dollar ;
float bp = ( 1 / 1 . 487 ) ;
float frnc = ( 1 / 0 . 172 ) ;
float deutschmark = ( 1 / 0 . 584 ) ;
float yen = ( 1 / 0 . 00955 ) ;
float ind = ( 1 / 0 . 013 ) ;
cout << " enter the Dollars for Conversion : \ n " ;
cin >> dollar ;
cout << " Indian Rupees : " << ind * dollar << endl ;
cout << " British Pounds : " << bp * dollar << endl ;
cout << " French franc : " << frnc * dollar << endl ;
cout << " German Deutschmark : " << deutschmark * dollar << endl ;
cout << " Japanese Yen : " << yen * dollar << endl ;
return 0 ; 
}

Output:

When running this application, users will interact with it using the methods outlined below to resolve their concerns. The general situation is illustrated as follows.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience