Income tax rate calculator in c++ I have been trying to learn c++ for the sake of being comfortable with a second language. I found a project that seemed relatively easy, although it may not be implemented perfectly, it was a simple project.
I create a std::map&lt;double, std::string&gt;, which will represent the tax rate as a double, and the required income as a string. A user will input their income and the maximum amount of taxes to be paid in dollars will be returned. Here is the code:
#include &lt;stdio.h&gt;
#include &lt;iostream&gt;
#include &lt;cmath&gt;
#include &lt;map&gt;
#include &lt;iomanip&gt;

double TaxesDue(double &amp;income);
double HighestRate(double &amp;income);

std::map&lt;double, std::string&gt; taxRate =
{
    {  0.35, &quot;499999&quot; },
    {0.31, &quot;349999&quot;},
    {0.25,&quot;249999&quot;},
    {0.21,&quot;169999&quot;},
    {0.18,&quot;119999&quot;},
    {0.14,&quot;79999&quot;},
    {0.10,&quot;44999&quot;},
    {0.05,&quot;29999&quot;}
};


int main()
{
    double income;

    std::cout &lt;&lt; &quot;Enter your income: &quot; &lt;&lt; std::endl;
    std::cin &gt;&gt; income;

    double taxesDue = TaxesDue(income);
    std::cout &lt;&lt; taxesDue &lt;&lt; std::endl;
}

double TaxesDue(double &amp;income)
{
    double totalTaxes = 0.0;
    double taxDiff = 0.0; //as taxes are calculates, subtract the income

    double highestRate = HighestRate(income);

    for (double i = income; i &gt; 29999; )//knowing the lowest tax rate is 0.05
    {
        taxDiff = (income - std::stod(taxRate[highestRate]));
        totalTaxes += (highestRate * taxDiff);
        i -= taxDiff;
        highestRate = HighestRate(i);
    }

    return totalTaxes;
}

double HighestRate(double &amp;income)
{
    /*
    std::map&lt;double, std::string&gt; taxRate =
    {
        {  0.35, &quot;499999&quot; },
        {0.31,&quot;349999&quot;},
        {0.25,&quot;249999&quot;},
        {0.21,&quot;169999&quot;},
        {0.18,&quot;119999&quot;},
        {0.14,&quot;79999&quot;},
        {0.10,&quot;44999&quot;},
        {0.05,&quot;29999&quot;}
    };
    */

    if (income &gt; std::stod(taxRate[0.35]))
    {
        return 0.35;
    }
    if (income &gt; std::stod(taxRate[0.31]))
    {
        return 0.31;
    }
    if (income &gt; std::stod(taxRate[0.25]))
    {
        return 0.25;
    }
    if (income &gt; std::stod(taxRate[0.21]))
    {
        return 0.21;
    }
    if (income &gt; std::stod(taxRate[0.18]))
    {
        return 0.18;
    }
    if (income &gt; std::stod(taxRate[0.14]))
    {
        return 0.14;
    }
    if (income &gt; std::stod(taxRate[0.10]))
    {
        return 0.10;
    }
    if (income &gt; std::stod(taxRate[0.05]))
    {
        return 0.05;
    }

    return 0.0;
}

My biggest thing is trying to improve the HighestRate(double &amp;income) method. How should I convert the if (income &gt; std::stod(taxRate[x])) to make the code better? Meaning, are there any libraries that I could use to find 'where value &gt; then this std::map value'?
Also I think that I should probably change the std::map&lt;double, std::string&gt; to std::map&lt;double, double&gt;.
This isn’t a bad idea for a learning project, and I’d say it’s implemented quite well.
Before I dive into the code itself, I’m going to do a high-level design review.
Design review
You’re using std::map backwards
So you want a list of pairs of values, where one value is the tax rate and the other income lower bound for that tax rate. In your code you made the tax rate the lookup key, and the lower income bound the value.
The problem with that is that what you want to do is use the income to lookup the tax rate. Since the tax rate is the key in your map, that means you actually have to manually go through the map, checking each entry and inspecting the value.
If your map were the other way around—with the thing you actually want to lookup, the income, as the key—the lookup code would be trivial:
// income lower bound is the key, tax rate is the value
auto const taxRate = std::map&lt;double, double&gt;{
    {499'999, 0.35},
    {349'999, 0.31},
    // and so on
};

double HighestRate(double income)
{
    // lower_bound() finds the key that is NOT LESS than the argument given
    // (in other words, the key that is greater or equal). So whatever income
    // you give it, it will give you the NEXT greater tax bracket. That means
    // we have to BACKWARDS one tax bracket to get the proper answer.
    //
    // If the data were encoded differently, this could be much simpler, but
    // you have to be careful not to change the logic.

    auto p = taxRate.lower_bound(income);

    // If we got the first tax bracket, there is no lower tax bracket... so
    // no taxes due.
    if (p == taxRate.begin())
        return 0.0;

    // Go backwards one tax bracket.
    --p;

    // Now just return the rate.
    return p-&gt;second;
}

Actually, the code is even simpler if you don’t use HighestRate():
double TaxesDue(double income)
{
    double totalTaxes = 0.0;

    // Starting tax bracket:
    auto p = taxRate.lower_bound(income);

    // Convert the starting tax bracket iterator to a REVERSE iterator so we
    // can go backwards (from highest tax bracket down to lowest).
    for (auto r = std::map&lt;double, double&gt;::reverse_iterator{p}; r != taxRate.rend(); ++r)
    {
        // For each tax bracket:

        // 1) subtract the lower bound from the income to get the amount
        //    taxable in that bracket
        auto taxable_amount = income - r-&gt;first;

        // 2) calculate the taxes, and add to the total
        totalTaxes += taxable_amount * r-&gt;second;

        // 3) the remaining income is everything not yet taxed... which is
        //    the same as the lower bound of the bracket
        income = r-&gt;first;
    }

    return totalTaxes;
}

Don’t take the two functions above too seriously; I didn’t test them, and I didn’t really think too hard writing them, so there may be mistakes.
The point I want to make here is about the shape of your map. You should ask what you’re using the map for; what are you using to search? In your case, you are using the income to search the map (to find the tax rate). That means the income should be the key… not the tax rate.
An extra map tip
Notice in the functions I wrote above that I had to go backwards and use reverse iterators, all of which increased the complexity quite a bit. Well, the cause of that is that std::map will store its elements in increasing order, starting from the lowest to the highest. But when you’re calculating taxes, you want to go the opposite way: you want to start at the highest tax bracket, and work your way down. That’s the way you wrote the data, too: from the largest to smallest tax bracket.
There is way to flip the order of std::map. std::map has 3 template parameters (well, actually 4, including the allocator). The third template parameter is the comparator function, which defaults to std::less. So to flip the order, all you got to do is use std::greater instead.
Observe:
auto const taxRate = std::map&lt;double, double, std::greater&lt;&gt;&gt;{
    {499'999, 0.35},
    {349'999, 0.31},
    // and so on
};

double TaxesDue(double income)
{
    double totalTaxes = 0.0;

    // Easy peasy.
    //
    // (Just note we switched to upper_bound() because the
    // greater-than/less-than logic is reversed.)
    for (auto p = taxRate.upper_bound(income); p != taxRate.end(); ++p)
    {
        auto taxable_amount = income - p-&gt;first;

        totalTaxes += taxable_amount * p-&gt;second;

        income = p-&gt;first;
    }

    return totalTaxes;
}

One more thing I should mention: I noticed you used the tag “hash map”. You’re not actually using a hash map; you’re using a normal map. In the standard library, the hash map is named std::unordered_map… but you do not want to use that for this case, because it is—as the name says—unordered… and you want ordering to make searching and doing calculations easier.
A note about money and floating point values
While it’s fine for practice code, you should never, ever use floating point types like double for currency.
To see why, try running this simple program:
#include &lt;iostream&gt;

auto main() -&gt; int
{
    auto my_cash = 100.0;

    // Set up cout to print cash values nicely:
    std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
    std::cout.precision(2);

    std::cout &lt;&lt; &quot;I have in my account: &quot; &lt;&lt; my_cash &lt;&lt; &quot;\n\n&quot;;

    my_cash += 1e24;
    std::cout &lt;&lt; &quot;The bank screwed up and deposited a septillion dollars!\n&quot;;
    std::cout &lt;&lt; &quot;I have in my account: &quot; &lt;&lt; my_cash &lt;&lt; &quot;\n\n&quot;;

    my_cash -= 1e24;
    std::cout &lt;&lt; &quot;The bank took their septillion dollars back.\n&quot;;
    std::cout &lt;&lt; &quot;I have in my account: &quot; &lt;&lt; my_cash &lt;&lt; &quot;\n\n&quot;;

    std::cout &lt;&lt; &quot;:(\n&quot;;
}

Example output:
I have in my account: 100.00

The bank screwed up and deposited a trillion dollars!
I have in my account: 999999999999999983222784.00

The bank took their trillion dollars back.
I have in my account: 0.00

:(

A better idea is to use an integer type fixed to the smallest money fraction you could want to work with. For example, instead of using a double value of 100.0 dollars, you might use an int value of 10000 cents. Or if you need more precision, you might use millionths of a dollar, so $100 would be an int with value 100'000'000. If int is too small, you’d use long or long long or std::int_fast64_t instead.
Then what you’d do is make a class for monetary values, to make working with them painless and transparent. The class would simply wrap your integer type, and then provide a nice interface so you could write code like:
class money_t
{
    // ...

private:
    std::int_fast64_t _value;
};

constexpr auto calculate_taxes(money_t income)
{
    return income * 0.05; // 0.05 is the tax rate
}

auto income = 100_dollars;

auto taxes = calculate_taxes(income);

std::cout &lt;&lt; &quot;you pay &quot; &lt;&lt; taxes &lt;&lt; &quot; in tax.\n&quot;;
std::cout &lt;&lt; &quot;you have &quot; &lt;&lt; (income - tax) &lt;&lt; &quot; left over.\n&quot;;

// the output is automatically nicely formatted as:
//      you pay $5.00 in tax.
//      you have $95.00 left over.

I would recommend starting with something as simple as:
using money_t = std::int_fast64_t; // or &quot;= long long;&quot; or whatever

… then building up to a proper money_t class. That could be your next project! C++ is a strongly-typed language, and I always tell my students that if you get the types right in C++, then everything else because easy. Making a monetary value type isn’t hard, but doing it well will take some work, and teach you a lot about the language along the way.
Code review
#include &lt;stdio.h&gt;

This is not a C++ header. The proper header here would be &lt;cstdio&gt;… but honestly, I can’t see why you need it.
You also don’t use anything from &lt;cmath&gt; or &lt;iomanip&gt; so far as I can tell.
But you do use std::stod()… which is in &lt;string&gt;… which you don’t include. It “works” probably because &lt;string&gt; is being included by something else… but you can’t count on that.
double TaxesDue(double &amp;income);
double HighestRate(double &amp;income);

It is very rare to take function parameters by non-const lvalue reference. There are only a few special cases where that’s normally done.
When you take an argument by a non-const reference, you are telling the people reading your code that you intend to change that value. So when I see TaxesDue(income), I assume income’s value is going to change after the function call. The compiler will also assume that, which can prevent optimizations.
If you’re not going to change the value of the argument, it should be const:
double TaxesDue(double const&amp; income);
double HighestRate(double const&amp; income);

However, double is a fundamental type, so you don’t really need to take it by reference at all. It doesn’t hurt, though.
Also, note that the standard practice in C++ is to put the type modifier with the type:

double &amp;income: this is C style.
double&amp; income: this is C++ style.

std::map&lt;double, std::string&gt; taxRate =

You might want to make this const.
    double income;

    std::cout &lt;&lt; &quot;Enter your income: &quot; &lt;&lt; std::endl;
    std::cin &gt;&gt; income;

Couple things here. You should put the variable declaration as close as possible to the point of initialization. This is better:
    std::cout &lt;&lt; &quot;Enter your income: &quot; &lt;&lt; std::endl;

    double income;
    std::cin &gt;&gt; income;

It’s also wise to avoid uninitialized variables. It’s kinda okay if you do what I did just above, and put the double income; RIGHT above the std::cin that actually initializes it. But the way you wrote it, with the double income; several lines away from where it’s initialized… that’s dangerous.
One way to avoid initialized variables is to use the more modern practice of “always auto”:
// double income;       // &lt;- bad, uninitialized
auto income = double{}; // &lt;- better, cannot possibly be uninitialized

Finally, avoid std::endl. I know lots of tutorial code shows to use it, but it’s almost always wrong (or more charitably: unnecessary). Every use of std::endl in your code is wrong; in every case it forces a flush of the output stream unnecessarily.
If you want a newline, don’t use std::endl. Just use \n:
int main()
{
    std::cout &lt;&lt; &quot;Enter your income: \n&quot;;

    auto income = double{};
    std::cin &gt;&gt; income;

    auto taxesDue = TaxesDue(income);
    std::cout &lt;&lt; taxesDue &lt;&lt; '\n';
}

TaxesDue() is cool. It could be simplified and made much more efficient, but the problems aren’t actually in the function, they’re in the way the data is structured, as I mentioned in the design review.
The only big problem in TaxesDue() is the magic number 29999. You shouldn’t hard code that in the function. You should use the tax rate map; just get the income lower bound from the lowest tax bracket… which, with your current design, is just std::stod(taxRate.begin()-&gt;second). (But if you swapped the map key and value, and used doubles, it would be taxRate.begin()-&gt;first.)
So that leaves HighestRate():
double HighestRate(double &amp;income)
{
    /*
    std::map&lt;double, std::string&gt; taxRate =
    {
        {  0.35, &quot;499999&quot; },
        {0.31,&quot;349999&quot;},
        {0.25,&quot;249999&quot;},
        {0.21,&quot;169999&quot;},
        {0.18,&quot;119999&quot;},
        {0.14,&quot;79999&quot;},
        {0.10,&quot;44999&quot;},
        {0.05,&quot;29999&quot;}
    };
    */

    if (income &gt; std::stod(taxRate[0.35]))
    {
        return 0.35;
    }
    if (income &gt; std::stod(taxRate[0.31]))
    {
        return 0.31;
    }

    // ...

There is a lot of unnecessary repetition here. Take the tax rate for example: 0.35 is repeated three times, once in the tax rate map (which is fine), then twice in HighestRate().
Unfortunately, this can’t be simple, because you have the map backwards. If the income were the key, no problem, you just do a normal map lookup with lower_bound() (like I demonstrated in the design review section). But because the income is the value, and the rate is the key, you have to do this the hard way.
What you have to do is iterate through the map, checking the value. Not only that, you also have to make sure you get the largest value. Something like:
double HighestRate(double income)
{
    auto highest_amount = 0.0; // or &quot;= std::numeric_limits&lt;double&gt;::lowest();&quot;
    auto result = 0.0;

    for (auto&amp;&amp; [rate, amount_s] : taxRate)
    {
        auto amount = std::stod(amount_s);

        if ((income &gt; amount) and (amount &lt; highest_amount))
            result = rate;
            
    }

    return result;
}

Which, as you can see, is pretty complicated. That’s why you really want the income to be the key.