vendredi 16 février 2018

IF statement won't let me put in decimals

When I put in a decimal for box length. My if statement counts it as an INVALID INPUT. So if I put in 50.2, it is an INVALID INPUT.

#include <stdafx.h
#include <iostream>
#include <string>

int main()
{
    int boxlength = 0;
    cin >> boxlength;

    if(boxlength <= 0)
    {
        cout << "invalid input." << endl;
        system("pause");
        return 0;
    }
    else
    {
        cout << "blah"; 
    }

    system("pause");
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire