-3

I'm extremely new to C++ (I only started the course on it about 3 weeks ago) and I don't understand why this small program I'm trying to execute won't run. Here's the code

#include <iostream>
using namespace std;

int main()
{
    int A;
    int Y;
    A = 5;
    Y = 1;
    cout << Y = ++A << endl;
    return 0;
}

Note: I've tried writing it outside the block and I get back the error "invalid operands of types 'int' and '' to binary operator<<'. I've also tried declaring and initializing it in the same line and the same result. I'm really lost I've experimented for the last hour and no breakthroughs.

HelloWorld
  • 2,392
  • 3
  • 31
  • 68

1 Answers1

0

The problem is with the equal sign, aka the assignment operator in your cout line. Take that out.

cout << Y << " " << ++A << endl;

Also for future note when asking StackOverflow questions please tell us what you are trying to do and what you expect to happen.

Describing what your code is supposed to do is also a major point of TDD (Test Driven Development) which you should learn early on because it is so effective and useful.

Zan Lynx
  • 53,022
  • 10
  • 79
  • 131