error C2106: '=' : left operand must be l-value

for (int m=0;i<4 && i%2==0; m*m =i)
{
cout<<"Multiplication of all positive even numbers which are greater than N: "<<i<<endl;
}

Recommended Answers

All 19 Replies

A for loop is like a while loop, note the components below

for (int m = 0; m < 4; m++ )
int m = 0;
while ( m < 4 )
{

    
m++ }

In your code you have the initializer int m = 0
You have the comparison, but no definition for <i>
and you really should have parenthesis around the (i%2)==0
Finally your other problem m*m=i I think you may have
meant m*=i. You are doing an assignment m*m is not an assignment!

for (int m=0;i<4 && i%2==0; m*m =i)

"m*m =i "

Lets see , let m = 5, then

5 * 5 = i
---------------
5 * 5 = 0  /// 25 = 0  // = false
5 * 5 = 1;// 25 = 1 // false
5 * 5 = 2;// 25 = 2 // false
5 * 5 = 3//25 = 3 //false
// so on until i = 25, then it would be true, but has no effect on the 
loop

Did that make sense? Obviously m*m =i , is not what you
want to do. I think you are looking for is what wildgoose posted.

if(N<4&&(N%2)==1)
{
cout<<"The program can not be executed "<<endl;
}
	
else(N>4&&(N%2)==0);
{
result=N*N;   
cout<<"Multiplication of all positive even numbers which are greater than N: "<<result<<endl;                              
}


What i am trying to achive is when i enter the 4 numbers, all the positive even numbers greater 4 entered by a user should be multiplied by each other and say if only one positive even number is been entered by the user then that should multiplied by 1.

And if the user does not enter any prositive even number then the program should give and error.

if(N<4&&(N%2)==1)
{
cout<<"The program can not be executed "<<endl;
}
	
else(N>4&&(N%2)==0);
{
result=N*N;   
cout<<"Multiplication of all positive even numbers which are greater than N: "<<result<<endl;                              
}

What i am trying to achive is when i enter the 4 numbers, all the positive even numbers greater 4 entered by a user should be multiplied by each other and say if only one positive even number is been entered by the user then that should multiplied by 1.

And if the user does not enter any prositive even number then the program should give and error.

nProduct = 1
for (int i = 0; i < 4; i++)
    if ((ary[i] > 4) && !(ary[i] & 1))
       nProduct = nProduct * ary[i];
    endif
endfor

if (1 ==nProduct) then error

Hi,

Thanks for the reply, but we are not to use ary, then how would this be done.

nProduct = 1
for (int i = 0; i < 4; i++)
    input v
    if ((v > 4) && !(v & 1))
       nProduct = nProduct * v;
    endif
endfor

if (1 ==nProduct) then error
{
	nProduct = 1;
	for (int i = 0; i < 4; i++)
 
		{
		if ((N > 4) && !(N & 1))
		nProduct = nProduct * N;
		cout<<"Multiplication of all positive even numbers which are greater than N: "<<nProduct<<endl; 
		}
	}

	if (1 ==nProduct)
	{
	cout<<"The program can not be executed "<<endl;
	}
}

This iis the code i have written and even after what you have given i am unable to get my outcome.

hey the condition is correct but how do u show than u'll enter 4 numbers .???

hey the correct question is :::: multiplication of all the positive even numbers which are greater than N. if 1 even number greater than N is entered from the keyboard the entered number should be multiplied by 1. if no even number greater than N are entered, the program should display an approriate message.

The user will enter the 4numbers and it will display on the screeen, if you see i am getting the user to enter to numbers...

How do you know the question?

but the id condition says that
if ((N > 4) && !(N & 1))
what is n & 1 is it says that its positive ????

i have the same question for my assignment

Which uni or campus are you from?

cqu sydney . hey so the program is correct rite ??? ...

I have the same question for my assignment as well.. :) CQu sydney..
Anyone completed so far?

Hey guys,

If I'm understanding your problem correctly, then it seems to me like you want the program to look similar to the following outline:

#include <iostream>

using namespace std;

int main(void)
{

      int nUserNum;

     //set the next variable equal to 1 so that if the user enters
    //only one applicable number, it is multiplied by 1

      int nTotalNum=1;

      for(int i=0;i<4;i++)
      {
	//ask user to enter their number and store it in nUserNum

	if(nUserNum > 4 && nUserNum % 2 == 0)
	{
		//multiply nTotalNum by nUserNum and store in 
                               //nTotalNum
	}
	
              //this next part insures that the user receives an error
             //message if they don't enter an applicable number

	if(i == 3 && nTotalNum == 1)
	{
		//give user error message
	}
      }

     //Display the user's total using the nTotalNum variable
	
      return 0;
}

Hopefully that sets you guys on the correct track.

-D

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.