Calculator While Loop - I need help...

I'm trying to create a loop in which when the float var 'a' does not equal an integer, it will repeat. This is a small section of a calculator and I'm just trying to make it fool proof so you can enter only a number and leave everything out.

Whenever I build and run the code, when it reaches the loop, it repeats itself over and over again without asking for any user input.

1
2
3
4
5
6
7
8
9
10
11
12
float a, b, x;
    string y;

    cout << "Calculator 2016" << endl;
    cout << "Insert a Number:" << endl;
    cin >> a;
    while (!(a / a == 1)){
       cin >> a;
       system("CLS");
       cout << "That is not a valid number \n" << "Insert a Number:\n";

    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <cmath>//for ceilf;

using namespace std;

int main()
{
    bool fQuit = false;
    while(!fQuit)
    {
        cout<<"Insert number: \n";
        float a;
        cin>>a;
        if(ceilf(a)==a)
        {
            fQuit = true;
            break;
        }
    }
}
Last edited on
Topic archived. No new replies allowed.