Question

PLEASE, CLEARLY EXPLAIN THE ANSWER OF THE FOLLOWING QUESTION: - What is wrong with the following...

PLEASE, CLEARLY EXPLAIN THE ANSWER OF THE FOLLOWING QUESTION: -

What is wrong with the following code snippet?

cout << "Please enter a number: ";

cin >> b;

if (b > 100)

   cout << "Your number " << b << endl;

   cout << " was greater than 100" << endl;

  1. It has a syntax error.
  2. Nothing is wrong.
  3. Braces should have been included after the if() statement to clarify which statements are conditional.
  4. The comparison should be (b < 100).
0 0
Add a comment Improve this question Transcribed image text
Answer #1
If there is no {} after if statement then only the first statement after it consider to be in the if block.

So, we have to use {} and keep two statements inside it.

FIX:
-------
cout << "Please enter a number: ";
cin >> b;
if (b > 100){
   cout << "Your number " << b << endl;
   cout << " was greater than 100" << endl;
}
Answer:
Braces should have been included after the if() statement to clarify which statements are conditional.
Add a comment
Know the answer?
Add Answer to:
PLEASE, CLEARLY EXPLAIN THE ANSWER OF THE FOLLOWING QUESTION: - What is wrong with the following...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Briefly explain what is wrong (exactly 1 error) with the following code. auto input =...

    1. Briefly explain what is wrong (exactly 1 error) with the following code. auto input = 0.0; cout << "Enter input: "; cin >> input; cout << "Result 1 = " << 1.0 / input << endl; cout << "Result 2 = << input * input 2 * input << endl; cout << "Result 3 = << input + (9- input) << endl; 11

  • QUESTION 1 What is the output of the following code snippet? int main() { bool attendance...

    QUESTION 1 What is the output of the following code snippet? int main() { bool attendance = false; string str = "Unknown"; attendance = !(attendance); if (!attendance) { str = "False"; } if (attendance) { attendance = false; } if (attendance) { str = "True"; } else { str = "Maybe"; } cout << str << endl; return 0; } False True Unknown Maybe QUESTION 2 What is the output of the following code snippet? #include <iostream> #include <string> using...

  • What is wrong with the following code snippet? int main() { int width = 10; height...

    What is wrong with the following code snippet? int main() { int width = 10; height = 20.00; cout << "width = " << width << " height = " << height << endl; return 0; } The code snippet uses an uninitialized variable. The code snippet uses an undefined variable. The code snippet attempts to assign a decimal value to an integer variable. The code snippet attempts to assign an integer value to a decimal variable.

  • 51. What is the output of the following code snippet? int number = 0; int ptr_num...

    51. What is the output of the following code snippet? int number = 0; int ptr_num -&number ptr_num 60; number-80 cout < "ptr num << endl b, 60 c. 80 d. the address of number Answer 52. What is the output of the following code snippet? double num-0.0; double* ptr = &num; num = 15.0; ptr ptr 15.0 cout << num <<"ptr <<endl; a. 15 15 b. 15 30 С. 30 15 d. 30 30 Answer: 53. What is the...

  • What is wrong, if anything, with the following code? ​ double price = 0; cout <<...

    What is wrong, if anything, with the following code? ​ double price = 0; cout << "Item price: "; cin >> price; do { cout << "Total cost: $" << price + price * .05 << endl; cout << "Item price: "; } while (price > 0); ​​

  • What is the output of the following code snippet? (If there is some kind of syntax...

    What is the output of the following code snippet? (If there is some kind of syntax error indicate this by marking "error" in your answer choice) 1.        int fly = 5; int x;        if (fly-- > 5)               x = 5;        else               x = 2;        if (x++ > 3)               cout << x;        cout << fly << endl; 2.   int i = 0;        bool b = i == 0 || i++ > 0;        if (!b)               cout << i << endl;        else               cout...

  • Please answer both questions thank you. Question 49 (1 point) What is wrong with the following...

    Please answer both questions thank you. Question 49 (1 point) What is wrong with the following code snippet? for (int i 1; i <= 5; i++) { int squared = i + i; System.out.println(i + IT "! squared = + squared); } System.out.println("Last square = " + squared); calculation error variable scope error O nothing incorrect use of for loop Question 47 (1 point) What are the values of num1 and num2 and result after the execution of mystery (num1,...

  • 1.Which of the following is the correct code snippet for throwing a pair of 12-sided dice...

    1.Which of the following is the correct code snippet for throwing a pair of 12-sided dice to get a sum of the numbers on two dice between 2 and 24 with different probabilities 2 * (rand() % 11 + 2) rand() % 23 + 2 (rand() % 12) + (rand() % 12) (rand() % 12 + 1) + (rand() % 12 + 1) 2.What would be the correct replacement for the following if () statement ? if (0 > temperature...

  • Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string>...

    Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; //function void displaymenu1(); int main ( int argc, char** argv ) { string filename; string character; string enter; int menu1=4; char repeat; // = 'Y' / 'N'; string fname; string fName; string lname; string Lname; string number; string Number; string ch; string Displayall; string line; string search; string found;    string document[1000][6];    ifstream infile; char s[1000];...

  • Can you please explain what does each sentence mean and give an example if it’s possible?....

    Can you please explain what does each sentence mean and give an example if it’s possible?. I need to have answers for all of them please Assignment Statements- Input- cin >> Output--cout << endl<"n" Output formatting Arithmetic operators +-'* / % Relational Operators-=-= ++- Logical Operators ! && II Evaluating Expressions of mixed type Evaluating Boolean Expressions Type Conversion, Implicit Coersion Explicit-Type Casting Control Structure: Sequence, decision (branching), looping (repetition) if, if-else, if/else-if/else, nested ifs switch statement conditional statement while...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT