What is the incorrect action and why does it occur?

Specification: Check to see if the user’s input is a 0 or a 1. If it is a 0 or a 1, write out Hello World.```
#include
using namespace std;
int main()
{
int user_input;
cout << “\nEnter an integer.”;
cin >> user_input;
if(user_input == 0 || 1)cout << “\nHello World”;
return 0;
}
```


The problem with this code is that, no matter what the input value is, the program will always write out Hello World.

The error is in the way the if statement is written. By writing the statement in this manner, the ||1 (OR 1) is always true.

The fix involves writing the if statement like this:
```
if(user_input == 0 || user_input == 1)
```

Computer Science & Information Technology

You might also like to view...

If you type ____ into a new email message, Outlook fills in the email address for you.

A. the second half of an email address B. your contact's initials C. a code associated with a contact's name D. the first few letters of a contact's name

Computer Science & Information Technology

The method that must be implemented in a class using the Comparable interface is:

(a) public Object compareTo(Object other) (b) public Boolean compareTo(Object other) (c) public int compareTo(Object other) (d) none of the above

Computer Science & Information Technology

Which of the following would cause the error #DIV/0! to appear?

A) Invalid arguments in the function B) Misspelled word C) Formula attempts to divide a value by zero or an empty cell D) Invalid range name

Computer Science & Information Technology

The process of creating a copy of your files at a location other than on your computer is called ________

Fill in the blank(s) with correct word

Computer Science & Information Technology