Manipulating 4 inputs I have the following assignment:


  A program that takes four (4) inputs then using a conditional
  statement does the following:
  
  
  Display the values that are below or equal to 25.
  Multiply the values that are below 20 with each other.
  Add the values that are above 25 with each other.
  


I've successfully solved all of them as they're pretty easy, however I want to ask a couple of things along with getting feedback from you.  


I know that using less variables is always a better choice if you can do it, it might not matter on such small scale projects but I believe it's useful to get in the habit head-on. So in this specific example code, can I use a single var instead of 4 different ones? I know I can for the second and third tasks, however what about the third? Can I still list the inputs that are less than or equal to 25?
What tips do you have to make the code readable and even more easy to understand?


Also keep in mind that using loops, arrays, functions ... is not allowed so I would be glad if we keep our discussion limited to conditionals only.

#include "stdafx.h"
#include "iostream"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    float val1, val2, val3, val4;
    float sum = 0, multiply = 1;

    cout &lt;&lt; "Enter the first number: ";
    cin &gt;&gt; val1;
    if(val1 &lt; 20) {
        multiply *= val1;
    } else if(val1 &gt; 25) {
        sum += val1;
    }

    cout &lt;&lt; "Enter the second number: ";
    cin &gt;&gt; val2;
    if(val2 &lt; 20) {
        multiply *= val2;
    } else if(val2 &gt; 25) {
        sum += val2;
    }

    cout &lt;&lt; "Enter the third number: ";
    cin &gt;&gt; val3;
    if(val3 &lt; 20) {
        multiply *= val3;
    } else if(val1 &gt; 25) {
        sum += val3;
    }

    cout &lt;&lt; "Enter the fourth number: ";
    cin &gt;&gt; val4;
    if(val4 &lt; 20) {
        multiply *= val4;
    } else if(val4 &gt; 25) {
        sum += val4;
    }

    if(val1 &lt;= 25) cout &lt;&lt; "The number(s) below or equal to 25 are/is: " &lt;&lt; val1 &lt;&lt; endl;
    if(val2 &lt;= 25) cout &lt;&lt; "The number(s) below or equal to 25 are/is: " &lt;&lt; val2 &lt;&lt; endl;
    if(val3 &lt;= 25) cout &lt;&lt; "The number(s) below or equal to 25 are/is: " &lt;&lt; val3 &lt;&lt; endl;
    if(val4 &lt;= 25) cout &lt;&lt; "The number(s) below or equal to 25 are/is: " &lt;&lt; val4 &lt;&lt; endl;

    cout &lt;&lt; "When we multiply the numbers below 20 we get: " &lt;&lt; multiply &lt;&lt; endl;
    cout &lt;&lt; "When we add the numbers above 25 we get: " &lt;&lt; sum &lt;&lt; endl;

    return 0;
}
Regarding the number of variables:

For displaying all "small" values, you could introduce a variable of type string in which you save all small numbers. But since you haven't yet learned about functions and arrays, this would make your code much more complicated than it is now.

So for now, just keep the program as-is, using one variable per number.

In the rest of the review, I'm going straight from the top to the bottom of your code.

#include "stdafx.h"
#include "iostream"


The #include "stdafx.h" is fine. When an include file comes from your own project (which stdafx.h does), you should surround it with double quotes.

But all other include files (especially system headers like iostream) should not be enclosed in "double quotes" but in &lt;angle brackets&gt;. So it should be #include &lt;iostream&gt;.

using namespace std;


As soon as you start writing serious code, you should omit the using namespace std. This line imports several hundred names from the std namespace, such as min, max, sort, depending on the system headers you included. This can lead to confusion when you make typos or just forget to declare a function that is also defined in that namespace.

int _tmain(int argc, _TCHAR* argv[])
{
    float val1, val2, val3, val4;
    float sum = 0, multiply = 1;


Whenever possible, use the data type double instead of float, since it is more precise (15 digits instead of 7). 

    cout &lt;&lt; "Enter the first number: ";
    cin &gt;&gt; val1;


Imagine what happens when the user of the program doesn't enter a number here but simply types hello program. how are you today?. In that case val1 will not get any value, and whatever value was stored there before will be used by the program. This leads to unpredictable behavior.

To fix this, write the following code:

    if (!(std::cin &gt;&gt; val1)) {
        std::cerr &lt;&lt; "Error: could not read the first number\n";
        return 1; // Any nonzero value means failure.
    }


Continuing with your code …

    if(val1 &lt; 20) {
        multiply *= val1;
    } else if(val1 &gt; 25) {
        sum += val1;
    }


Very nice. Short and readable. I would just change the variable name multiply into product, since variables usually get passive names. Later, when you write functions, these will get the active names, like multiply two numbers.

    cout &lt;&lt; "Enter the second number: ";
    cin &gt;&gt; val2;
    if(val2 &lt; 20) {
        multiply *= val2;
    } else if(val2 &gt; 25) {
        sum += val2;
    }

    cout &lt;&lt; "Enter the third number: ";
    cin &gt;&gt; val3;
    if(val3 &lt; 20) {
        multiply *= val3;
    } else if(val1 &gt; 25) {
        sum += val3;
    }

    cout &lt;&lt; "Enter the fourth number: ";
    cin &gt;&gt; val4;
    if(val4 &lt; 20) {
        multiply *= val4;
    } else if(val4 &gt; 25) {
        sum += val4;
    }

    if(val1 &lt;= 25) cout &lt;&lt; "The number(s) below or equal to 25 are/is: " &lt;&lt; val1 &lt;&lt; endl;
    if(val2 &lt;= 25) cout &lt;&lt; "The number(s) below or equal to 25 are/is: " &lt;&lt; val2 &lt;&lt; endl;
    if(val3 &lt;= 25) cout &lt;&lt; "The number(s) below or equal to 25 are/is: " &lt;&lt; val3 &lt;&lt; endl;
    if(val4 &lt;= 25) cout &lt;&lt; "The number(s) below or equal to 25 are/is: " &lt;&lt; val4 &lt;&lt; endl;


The are/is doesn't look convincing. To make the output nice, you could count the numbers that are less than or equal to 25. Then, add the following code:

    if (lessOrEqual25Count == 0) {
        std::cout &lt;&lt; "No numbers are below or equal to 25.\n";

    } else {
        if (lessOrEqual25Count == 1) {
            std::cout &lt;&lt; "One number is below or equal to 25:";
        } else {
            std::cout &lt;&lt; lessOrEqual25Count &lt;&lt; " numbers are below or equal to 25:";
        }
        if (val1 &lt;= 25) std::cout &lt;&lt; " " &lt;&lt; val1;
        if (val2 &lt;= 25) std::cout &lt;&lt; " " &lt;&lt; val2;
        if (val3 &lt;= 25) std::cout &lt;&lt; " " &lt;&lt; val3;
        if (val4 &lt;= 25) std::cout &lt;&lt; " " &lt;&lt; val4;
        std::cout &lt;&lt; "\n";
    }


Continuing with your code …

    cout &lt;&lt; "When we multiply the numbers below 20 we get: " &lt;&lt; multiply &lt;&lt; endl;
    cout &lt;&lt; "When we add the numbers above 25 we get: " &lt;&lt; sum &lt;&lt; endl;

    return 0;
}


All in all, this is a nice program. It works fine, and it's good that you will learn about arrays and functions soon. They will really make programming easier, since currently you have to repeat large sections of your code over and over.