Ask Question

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; }

+2
Answers (1)
  1. 25 July, 12:16
    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?
Find 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 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