hello guys this is my first attempt in C++ and i am getting an error :(
the programs is made to read 20 numbers and find how many of them are even (like 2,4,6,20,40)

#include <iostream>

using namespace std;
int c[20];
int s = 0;
int i = 1;
int main()
{

  cout << "Enter the numbers followed by the ENTER key\n";

       loop:
            cin >> c[i];
            if(c[i]%2=0) //line with error
            {s++;}
            i++;
            if (i<=20) goto loop;

  cout << "done!\n Number of values: ";
  cout << s;
  system("PAUSE");
return 0;
}

and the error:

In function `int main()'
line 14: error: non-lvalue in assignment

Recommended Answers

All 2 Replies

One equal sign assigns a value. Two equal signs compare values.
Change

if(c[i]%2=0)

to

if(c[i]%2==0)

and it should get rid of that error.

But you probably shouldn't use goto.
You can use a for loop or a while loop or even a do while loop instead.

how could i miss that?
thank you so much !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.