GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-Jun-2009, 20:14
trevormoss trevormoss is offline
New Member
 
Join Date: Jun 2009
Posts: 3
trevormoss is on a distinguished road

Error c2106: '=' : left operand must be l-value


For some reason every time it comes to the line of code:
CPP / C++ / C Code:
if (number1 == 0.0 || number2 = 0.0)
it gives me an error: error C2106: '=' : left operand must be l-value



CPP / C++ / C Code:
#include <iostream>

using std::cout;
using std::cin;
using std::endl;
using std::string;


int main() //initialize main
{
	
	//declare variables
	char operation = ' ';
	double number1 = 0.0;
	double number2 = 0.0;
	double solution = 0.0;

	//gather data from end user
	cout << "This program will Add, Subtract, Multiply, or Divide two numbers.\n\n";
	cout << "Please enter the first number: ";
	cin >> number1;
	cout << "Please enter the second number: ";
	cin >> number2;
	cout << "Please enter 'a' for addition, 's' for subtraction, 'm' for multiplication, or 'd' for division: ";
	cin >> operation;




				//if it's division
		if (operation == 'd' || operation == 'D')
	       {
			if (number1 == 0.0 || number2 = 0.0)
			{
				cout << "Dividing by zero not allowed." << endl;
			}	
			else
			{
			solution = number2 / number1;
			cout << "The solution of the two numbers is: " << solution << endl;
			}
          }


		
	return 0;

}
  #2  
Old 16-Jun-2009, 23:43
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,335
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: error c2106: '=' : left operand must be l-value


Are you trying to set number2 to 0.0 or compare number2 to 0.0? Look carefully.
__________________

During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence?
  #3  
Old 17-Jun-2009, 01:20
manishsethi manishsethi is offline
New Member
 
Join Date: Jun 2009
Posts: 5
manishsethi is an unknown quantity at this point
Smile

Re: error c2106: '=' : left operand must be l-value


Also it should be '#include <iostream.h>' instead of '#include <iostream>'.
  #4  
Old 17-Jun-2009, 01:50
trevormoss trevormoss is offline
New Member
 
Join Date: Jun 2009
Posts: 3
trevormoss is on a distinguished road

Re: error c2106: '=' : left operand must be l-value


Still not getting it... I'm extremely new to C++, I just starting taking a college class on it...

CPP / C++ / C Code:
if (number1 == 0.0 || number2 == 0.0)
I don't get what you're saying about the set / compare...
  #5  
Old 17-Jun-2009, 02:08
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 1,032
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough

Re: error c2106: '=' : left operand must be l-value


Quote:
Originally Posted by manishsethi
Also it should be '#include <iostream.h>' instead of '#include <iostream>'.

Actually, iostream.h is deprecated in C++.
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #6  
Old 17-Jun-2009, 02:32
Kimmo Kimmo is offline
Member
 
Join Date: Mar 2007
Location: Finland
Posts: 283
Kimmo is a jewel in the roughKimmo is a jewel in the roughKimmo is a jewel in the rough

Re: error c2106: '=' : left operand must be l-value


Quote:
Originally Posted by trevormoss
Still not getting it... I'm extremely new to C++, I just starting taking a college class on it...
Then why did you fix the problem:
CPP / C++ / C Code:
if (number1 == 0.0 || number2 == 0.0)
By accident?

Quote:
I don't get what you're saying about the set / compare...

In C++ '=' is the assignment operator, '==' is the comparison operator. If you need to compare two values, you use '==',
CPP / C++ / C Code:
std::string aString = "A guy"; // Assignment
std::string aString2 = "A boy"; // Assignment
if (aString == aString2) // Comparison
    std::cout << "A guy is a boy?" << std::endl;
else
    std::cout << "A guy is not a boy!" << std::endl;
if you need to assign a value to a variable (like you do at the beginning of your program), you need to use the '=' operator.

Also, shouldn't this
CPP / C++ / C Code:
if (number1 == 0.0 || number2 == 0.0)
be something like
CPP / C++ / C Code:
if (number1 == 0.0)
You cannot divide by zero, but you can divide a zero. Also, should this
CPP / C++ / C Code:
solution = number2 / number1;
be this instead:
CPP / C++ / C Code:
solution = number1 / number2;
Since you're only asking for "first number" and "second number", I think most people assume the "first number" is the first operand and not the other way around.
  #7  
Old 17-Jun-2009, 13:31
trevormoss trevormoss is offline
New Member
 
Join Date: Jun 2009
Posts: 3
trevormoss is on a distinguished road

Re: Error c2106: '=' : left operand must be l-value


Thank you very much, problem fixed.
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Link List In C Peter_APIIT C Programming Language 33 12-Jun-2008 14:33
Disabling left click? tvdoc Apache Web Server Forum 0 19-Jul-2007 15:06
triangle (polygon), drawing, sizing, and rotation programme using linked lists... promsan C Programming Language 12 14-May-2007 15:03
need help with a console menu system BullBuchanan C++ Forum 6 20-Aug-2006 15:46

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 03:02.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.