Temperature conversion table This is another solution for this challenge.

Problem statement:


  In this challenge, write a program that takes in three arguments, a
  start temperature (in Celsius), an end temperature (in Celsius) and a
  step size. Print out a table that goes from the start temperature to
  the end temperature, in steps of the step size; you do not actually
  need to print the final end temperature if the step size does not
  exactly match. You should perform input validation: do not accept
  start temperatures less than a lower limit (which your code should
  specify as a constant) or higher than an upper limit (which your code
  should also specify). You should not allow a step size greater than
  the difference in temperatures.


I want to learn more about C++, so if there is some cool C++ feature I could should have used, please comment (or include it in your answer).

#import &lt;iostream&gt;
#import &lt;cmath&gt;

#define COLUMN_SEPARATOR "\t| "
#define MAX_TEMP 500
#define MIN_TEMP -500

inline bool between(double x, double max, double min) {
    return max &gt;= x &amp;&amp; min &lt;= x;
}

void getInput(double &amp;lower, double &amp;upper, double &amp;step) {
    double temp1, temp2;
    std::cout &lt;&lt; "Please enter consecutively the upper and lower limits, both between " &lt;&lt;  MIN_TEMP &lt;&lt; " and " &lt;&lt; MAX_TEMP &lt;&lt; "." &lt;&lt; std::endl;
    std::cin &gt;&gt; temp1;
    std::cin &gt;&gt; temp2;
    while (!between(temp1, MAX_TEMP, MIN_TEMP) || !between(temp2, MAX_TEMP, MIN_TEMP)) {
        std::cout &lt;&lt; "At least one of the temperatures is out of bounds. Please reenter:" &lt;&lt; std::endl;
        std::cin &gt;&gt; temp1;
        std::cin &gt;&gt; temp2;
    }
    upper = std::max(temp1, temp2);
    lower = std::min(temp1, temp2);
    std::cout &lt;&lt; "Please enter a positive stepsize, smaller than the difference between the limits." &lt;&lt; std::endl;
    std::cin &gt;&gt; step;
    while (step &lt; 0 || step &gt; upper - lower) {
        std::cout &lt;&lt; "The stepsize is out of bounds. Please reenter:" &lt;&lt; std::endl;
        std::cin &gt;&gt; step;
    }
}

double toFahrenheit(double celsius) {
    return celsius*(9/5) + 32;
}

void printTable(double start, double end, double step) {
    std::cout &lt;&lt; "Celsius" &lt;&lt; COLUMN_SEPARATOR &lt;&lt; "Fahrenheit" &lt;&lt; std::endl;
    std::cout &lt;&lt; "=======" &lt;&lt; COLUMN_SEPARATOR &lt;&lt; "==========" &lt;&lt; std::endl;
    for (double i = start; i &lt; end; i += step) {
        std::cout &lt;&lt; i &lt;&lt; COLUMN_SEPARATOR &lt;&lt; toFahrenheit(i) &lt;&lt; std::endl;
    }
}

int main() {
    double start, end, step;
    getInput(start, end, step);
    printTable(start, end, step);
    return 0;
}


Sample run:




192:Challenges 11684$ ./a.out Please enter consecutively the upper and lower limits, both between -500 and 500.
3.692
65.937
Please enter a positive stepsize, smaller than the difference between the upper and lower limit.
5.3729
Celsius   | Fahrenheit
=======   | ==========
3.692 | 35.692
9.0649    | 41.0649
14.4378   | 46.4378
19.8107   | 51.8107
25.1836   | 57.1836
30.5565   | 62.5565
35.9294   | 67.9294
41.3023   | 73.3023
46.6752   | 78.6752
52.0481   | 84.0481
57.421    | 89.421
62.7939   | 94.7939
Looks like there are no Americans here. 30 degrees Celsius is about 90 degrees Fahrenheit, so something must be wrong in the conversion. Indeed, (9/5) is evaluated (at compile time) as an integer division, yielding 1. Change it to (9.0/5.0).