Ask Question
14 April, 18:14

What error occurs in the following program? #include using namespace std; int main () { int number1, number2, sum; cout <> number1; cout <> number2; number1 + number2 = sum; cout << "The sum of number 1 and number 2 is " << sum; return 0; }

+1
Answers (1)
  1. 14 April, 20:52
    0
    1. 'cout' was not declared in this scope.

    2. 'cin' was not declared in this scope.

    3. lvalue required as left operand of assignment.

    Explanation:

    The code gives the error cout and cin was not declare. This error means, we not include the library where they define.

    cout and cin is the input/output instruction and they include in the library iostream file.

    the last error is lvalue required as left operand of assignment.

    lvalue means the assignable value, we actually do the wrong assignment.

    number1 + number2 = sum;

    here, sum is is the assignment variable. so, it must be in the right side of the '=' operator.

    sum = number1 + number2;

    Now, the above is correct. the value number1 plus number2 is assign to sum.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “What error occurs in the following program? #include using namespace std; int main () { int number1, number2, sum; cout number1; cout ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers