DEV Community

Cover image for Piggy Bank
Scott Gordon
Scott Gordon

Posted on • Updated on

Piggy Bank

GitHub Repo
Console Output

#include <iostream>

int main(int argc, char const *argv[])
{
    double pesos = 0, reais = 0, soles = 0;
    const double pesos_usd = 0.048, reais_usd = 0.18, soles_usd = 0.25;

    std::cout << "Enter number of Colombian Pesos: ";
    std::cin >> pesos;

    std::cout << "Enter number of Brazillian Reais: ";
    std::cin >> reais;

    std::cout << "Enter number of Peruvian Soles: ";
    std::cin >> soles;

    double total_amount = (pesos * pesos_usd) + (reais * reais_usd) + (soles * soles_usd);
    std::cout << "US Dollars = $" << total_amount << "\n";

    return 0;
}
Enter fullscreen mode Exit fullscreen mode

Verify my C++

Photo by Jason Leung on Unsplash

Top comments (2)

Collapse
 
serkzex profile image
Mujtaba Aldebes • Edited

Cool task. You could extend your code to make it more dynamic and accurate over time. Instead of having hardcoded currency exchange rates, you could invoke some rest api (there are some free ones) to fetch "real-time" exchange rates. Hence your code will always be up to date.

Collapse
 
sagordondev profile image
Scott Gordon

Awesome suggestion thank you!