Question: in C++, when I run the program and input a char or string value, the cout < < The number is zero < < endl;

in C++, when I run the program and input a char or string value, the cout << "The number is zero" << endl; line executes. Does the cin statement read a char or string value as zero? or how can i make the else statement execute when I input a string or char value?

int number,

cout << "This program will determine wether a number is negative, positive, or zero" << endl;

<< "Enter a number: ";

cin >> number;

if (number == 0)

cout << "The number is zero" << endl;

else if (number > 0)

cout << "The number is positive!" << endl;

else if (number < 0)

cout << "The number is negative!" << endl;

else

cout << "You were instructed to enter a number!" << endl; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!