lundi 13 janvier 2020

While loop inside if-statement with the same condition inside?

One very experienced programmer wrote something like this:

#include <string>
using namespace std;

class Fraction
{
 float nominator;
 float denominator;

void load()
{
 cin>>nominator; cin>>denominator;
 if(denominator==0)
        {
          while(denominator==0)
          { 
            cout<<"denominator can not be equal 0!"<<endl;
            cin>>denominator;
          }
        }
}
};

I have no idea why there is an if statement. Is it really necessary? source here

It's my first post, I am not familiar with stackoverflow so sorry for mistakes :)

Aucun commentaire:

Enregistrer un commentaire