Why this code became infinite loop when entering floating number?

Viewed 18

Program to take negative input This program works perfectly with int but when inputting float it become infinite loop. why ?

#include<iostream>
using namespace std;
int main(){

     int positive = 0;
     
     while(positive>=0){
          cout<<"Enter number"; cin>> positive;
          if (positive<0){
               cout<<"yes it is negative";
          }
     }
     
     return 0;
}
0 Answers
Related