Ask Question

Type the statements below, correcting the one syntax error in each statement.

Hints:Statements end in semicolons, and string literals use double quotes.

cout << "Foretelling is hard." <<

end; cout << "Particularly ';

cout << "of the future." << endl. cout <<

"User num is: " <> endl;

Note: These activities may test code with different test values. This activity willperform two tests: the ±rst with userNum = 5, the second with userNum = 11.

+4
Answers (1)
  1. 22 August, 04:18
    0
    Corrected statements:

    cout<<"Foretelling is hard."<
    cout << "Particularly";

    cout << "of the future." << endl;

    cout << "User num is: " << userNum << endl;

    Explanation:

    Statement 1: cout << "Foretelling is hard." <
    Syntax Error generated when the statement is compiled: no match for 'operator<<' (operand types are 'std::basic_ostream' and '')

    This error is generated because "end" is used which is not valid. It should be replaced with endl which is used to insert a new line.

    So the corrected statement without syntax error is:

    cout << "Foretelling is hard." <
    The output of this corrected line is as following:

    Foretelling is hard.

    Statement 2: cout << "Particularly ';

    Syntax Error generated when the statement is compiled: missing terminating " character

    This error is generated because the one of the double quotations is missing in the statement and single quote is used instead which resulted in syntax error. So in order to correct this syntax error single quote ' should be replaced with double quotation mark ".

    So the corrected statement without syntax error is:

    cout << "Particularly";

    The output of this corrected line is as following:

    Particularly

    Statement 3: cout << "of the future." << endl.

    Syntax Error generated when the statement is compiled:

    'std::endl' does not have class type

    This error is produced because the statement did not end in semicolon. Instead it is ended with a period (.) placed after endl

    So in order to remove this syntax error; is placed instead of.

    So the corrected statement without syntax error is:

    cout << "of the future." << endl;

    The output of this corrected line is as following:

    of the future

    Statement 4: "User num is: " <> endl;

    Syntax Error generated when the statement is compiled:

    no match for 'operator>>' (operand types are 'std::basic_ostream' and '')

    This error is produced because extraction operator >> is being used instead of insertion operator <<. Here the value of userNum is to be displayed and next line is to be inserted so insertion operator << should be used in place of extraction operator which is used for input.

    So the corrected statement without syntax error is:

    cout << "User num is: " << userNum << endl;

    Now lets declare the variable userNum and assign it value 5 as:

    int userNum = 5;

    So output of this corrected line is as following:

    User num is: 5

    If tested for userNum=11 then the output is as following:

    User num is: 11
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Type the statements below, correcting the one syntax error in each statement. Hints:Statements end in semicolons, and string literals use ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers