Currency Converter: Euros to US Dollars in C++

This exercise is designed to help you understand how to work with floating-point numbers and user input/output in C++. You will build a basic currency converter that takes an amount in euros and converts it into US dollars using a fixed exchange rate.

In this program, the user will be prompted to enter the amount of euros they want to convert. The program will then apply a predefined conversion rate to calculate and display the equivalent amount in dollars.

This type of program is useful in financial applications, budgeting tools, travel utilities, and any scenario involving currency transactions. It reinforces the use of variables, mathematical expressions, and precision with decimals in C++.

Group

Introduction to C++

Objective

1. Declare two floating-point variables to hold the amount in euros and the result in dollars.
2. Define a constant variable for the exchange rate (e.g., 1 euro = 1.1 dollars).
3. Prompt the user to enter the amount in euros.
4. Multiply the amount by the exchange rate to get the value in dollars.
5. Display the converted amount with an appropriate message.

Perform a currency conversion (for example, euros to dollars).

Example C++ Exercise

 Copy C++ Code
#include <iostream> // Include the iostream library to enable input and output operations
#include <iomanip> // Include iomanip for controlling output precision

using namespace std; // Use the standard namespace

// Main function - starting point of the program
int main() {
    double euros, dollars; // Declare variables for euros and dollars
    const double exchangeRate = 1.1; // Define a constant for the euro to dollar conversion rate

    // Prompt the user to enter an amount in euros
    cout << "Enter the amount in euros: ";
    cin >> euros; // Read the amount in euros from user input

    // Convert euros to dollars by multiplying with the exchange rate
    dollars = euros * exchangeRate;

    // Display the result with two decimal places
    cout << fixed << setprecision(2); // Set precision for output
    cout << euros << " euros is equal to " << dollars << " US dollars." << endl;

    return 0; // Return 0 to indicate successful execution
}

 Output

Enter the amount in euros: 50
50.00 euros is equal to 55.00 US dollars.

Share this C++ Exercise


More C++ Programming Exercises of Introduction to C++

Explore our set of C++ Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of C++. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in C++.

  • Calculate the Perimeter of a Rectangle in C++

    This exercise focuses on computing the perimeter of a rectangle using basic arithmetic operations in C++. It’s a great way for beginners to get hands-on practice with input/output,...

  • Sum of the First N Natural Numbers in C++

    This exercise introduces the concept of summation using a loop in C++. You will create a program that calculates the sum of the first N natural numbers, where N is provided by the ...

  • Print the First 10 Fibonacci Numbers in C++

    This exercise helps you understand how to generate a sequence of numbers based on mathematical logic using iterative programming. Specifically, you'll write a program in C++ that p...

  • Hello World Program in C++

    The "Hello, World!" program is one of the simplest programs to write in any programming language. It serves as an introduction to the syntax and basic functionality of a programmin...

  • Sum of Two Numbers Entered by the User in C++

    This exercise introduces user input handling in C++ through a simple program that adds two numbers provided by the user. It's an ideal starting point for understanding how to work ...

  • Convert Celsius to Fahrenheit in C++

    This beginner-friendly exercise demonstrates how to perform a temperature conversion from Celsius to Fahrenheit using a basic arithmetic formula in C++. It's an excellent introduct...