Question:

"If not equal a number" in C Plus Plus?

by  |  earlier

0 LIKES UnLike

how you write "If not equal a number" in C Plus Plus ?

for example

int numb;

cout << "Enter a number" << endl;

cin >> numb;

if (numb!=a number)

{

cout << "That's is not a number";

}

 Tags:

   Report

1 ANSWERS


  1. #include &lt;iostream&gt;

    #include &lt;cstring&gt;

    using namespace std;

    int main(int argc, char * argv[]){

    char numb[100];

    //int verify will be used as a flag to check the whole string

    int verify=0;

    //Prompt for input

    cout&lt;&lt;&quot;Please enter a number&quot;;

    cin&gt;&gt;numb;

    for(int i=0; i&lt;strlen(numb);i++){

    if(numb[i].isdigit()){

    //Verify will be used to check and see if the input entered

    //is a number. It will work by incrementing every time it //passes the isdigit() checking function. If the value of it is //the same as the the length of the string entered then you //know that the input is valid

    verify++;

    }

    else{

    cout&lt;&lt;&quot;That was not a number&quot;&lt;&lt;endl;

    break;

    }

    }

    if(verify==strlen(numb){

    cout&lt;&lt;&quot;That was a number&quot;;

    }

    cin.get();

    return 0;

    }

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.