Why cant i reject Decimals? (C++)
<p>With this code: </p>

<pre><code>#include &lt;iostream&gt;
#include &lt;iomanip&gt;
using namespace std;

//Functions
int power(int base,int exp);
double energy(int z, int n);

//Main
int main() {


    const double E0(13.6),hce(1.24E-6),e(1.6E-19);
    int n1,n2,z;
    double E;
    cout &lt;&lt; "**************************************" &lt;&lt; endl;
    cout &lt;&lt; "Welcome to the energy level calculator\n" &lt;&lt; endl;
    cout &lt;&lt; "Please enter the atomic number, z: " &lt;&lt; endl;
    cin &gt;&gt; z;   //Ask for z
    cout &lt;&lt; "Please enter n for the initial energy level: " &lt;&lt; endl;
    cin &gt;&gt; n1;  //Ask for n1
    cout &lt;&lt; "Please enter n for the final energy level: " &lt;&lt; endl;
    cin &gt;&gt; n2;  //Ask for n2

    while(cin.fail()||z&lt;1||n1&lt;1||n2&lt;1){
        cout &lt;&lt; "\n\n\n\n\nPlease enter non-zero integers only, try again\n\n\n\n\n\n" &lt;&lt; endl;
        cout &lt;&lt; "**************************************" &lt;&lt; endl;
        cin.clear();
        cin.ignore();
        cout &lt;&lt; "Please enter the atomic number, z: " &lt;&lt; endl;
        cin &gt;&gt; z;   //Ask for z
        cout &lt;&lt; "Please enter n for the initial energy level: " &lt;&lt; endl;
        cin &gt;&gt; n1;  //Ask for n1
        cout &lt;&lt; "Please enter n for the final energy level: " &lt;&lt; endl;
        cin &gt;&gt; n2;  //Ask for n2
    }
    etc...
</code></pre>

<p>The program is only allowed to accept Integers
If i enter a decimal, such as 1.2 the program rejects the 1. but uses the 2 as z when it should be asking for input from the keyboard?
Can anyone help?</p>
