C++ Tutorial: Building a Currency Converter in Replit

Convert USD to other currency program

Welcome to this exciting journey into the world of C++ programming! If you’re a high school student curious about coding, you’re in the right place. Today, we’re going to create a moderately complex project: a Currency Converter. This project will not only introduce you to basic programming concepts in C++ but also provide a practical application you can expand on. We’ll be using Replit, an online coding platform, to write, run, and share our code easily.

Setting Up Your Environment on Replit

First things first, let’s set up our coding environment:

  1. Create a Replit Account: If you haven’t already, head to Replit.com and sign up.
  2. Start a New C++ Repl: Once logged in, click the “+ Create” button and select “C++” as your language.
  3. Name Your Project: You can name it something like “CurrencyConverter.”

Planning Our Project

Before diving into the code, let’s outline what our currency converter will do:

  • Accept input from the user in one currency (e.g., USD – United States Dollar).
  • Convert the input amount to another currency (e.g., EUR – Euro).
  • Display the converted amount to the user.

Writing the Code

Now, let’s start coding. Here’s the basic structure of our currency converter program:

#include <iostream>
#include <string>
#include <map>

// Function to perform currency conversion
double convertCurrency(double amount, std::string fromCurrency, std::string toCurrency) {
    // Conversion rates - ideally, these would be dynamically fetched from an API
    std::map<std::string, double> rates = {
        {"USDtoEUR", 0.85},
        {"EURtoUSD", 1.17},
        // Add more currency conversion rates here
    };

    std::string conversionPair = fromCurrency + "to" + toCurrency;

    if (rates.find(conversionPair) == rates.end()) {
        std::cout << "Conversion rate not found." << std::endl;
        return -1;
    }

    return amount * rates[conversionPair];
}

int main() {
    // Variables to store user input
    double amount;
    std::string fromCurrency, toCurrency;

    // User input
    std::cout << "Enter the amount to convert: ";
    std::cin >> amount;

    std::cout << "Enter the currency you are converting from (USD/EUR): ";
    std::cin >> fromCurrency;

    std::cout << "Enter the currency you are converting to (EUR/USD): ";
    std::cin >> toCurrency;

    // Perform conversion
    double convertedAmount = convertCurrency(amount, fromCurrency, toCurrency);

    // Output result
    if (convertedAmount != -1) {
        std::cout << "Converted amount: " << convertedAmount << " " << toCurrency << std::endl;
    }

    return 0;
}

Key Components Explained:

  • #include & #include : These lines include libraries that allow us to use input/output streams and the string data type.
  • #include : This includes the map library, enabling us to store currency conversion rates.
  • convertCurrency Function: This function takes the amount to be converted, the currency being converted from, and the currency being converted to. It looks up the conversion rate in the rates map and returns the converted amount.
  • int main(): The main function where our program starts. It gets user input for the amount and currencies, calls the convertCurrency function, and displays the result.

Testing Your Program

After copying the code into your Replit editor:

  1. Click the “Run” button at the top of the screen.
  2. When prompted, enter the amount you want to convert and specify the currencies.
  3. The program will display the converted amount.

Expanding the Project

Now that you have a basic currency converter, think about how you can expand it. Here are some ideas:

  • Add more currencies and conversion rates.
  • Implement functionality to dynamically fetch the latest conversion rates from an API.
  • Create a user-friendly menu to select currencies instead of entering them as text.

Conclusion

Congratulations! You’ve just built a functional currency converter in C++. This project introduces you to fundamental C++ programming concepts such as variables, input/output, conditionals, maps, and functions. Keep experimenting with your program and exploring C++ to build more complex and interesting projects. Happy coding!

SHARE WITH FRIENDS >

After-school Coding & Game Design Classes (Godot), Ottawa, Tutorials

20 Apr 2026

Godot Game Design for Teens in Ottawa: Find After‑School Classes + a Step‑by‑Step 2D Game Tutorial

After-school Live Virtual Scratch & Block Coding Classes For Kids, Phoenix

20 Apr 2026

Weekend Workshops & Summer Coding Camps for Phoenix Kids: Short Intensives in Scratch & Block Coding

After-school Live Virtual Scratch & Block Coding Classes For Kids, Phoenix

20 Apr 2026

Tech Requirements & Onboarding for Live Online Scratch Classes (Phoenix Families’ Checklist)

After-school Live Virtual Scratch & Block Coding Classes For Kids, Phoenix

20 Apr 2026

Hybrid & School‑Partnership After‑School Coding in the Phoenix Metro: Options for Scottsdale, Tempe, Chandler & Gilbert

After-school Live Virtual Scratch & Block Coding Classes For Kids, Phoenix

20 Apr 2026

How We Teach Scratch & Block Coding by Age: Elementary vs. Middle School Curriculum (Phoenix metro)

After-school Live Virtual Scratch & Block Coding Classes For Kids, Phoenix

20 Apr 2026

Instructor Qualifications & Safety for Live Virtual Scratch & Block Coding Classes — Phoenix Families’ Guide

After-school Live Virtual Scratch & Block Coding Classes For Kids, Phoenix

20 Apr 2026

Are live virtual Scratch classes effective for young learners? Evidence, best practices & Phoenix parent tips

After-school Live Virtual Scratch & Block Coding Classes For Kids, Phoenix

20 Apr 2026

Free trial & demos: How to book a live virtual Scratch class for kids in Phoenix

After-school Live Virtual Scratch & Block Coding Classes For Kids, Phoenix

20 Apr 2026

Pricing and packages for kids’ block coding classes in Phoenix: sibling discounts, make-ups & payment plans