error

This is a discussion on error within the C++ Programming forums, part of the General Programming Boards category; alright i've got a code to check for the effecincy of the fuel in a car here is the error ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    224

    Post error

    alright i've got a code to check for the effecincy of the fuel in a car

    here is the error in it

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

    here is the code were the error is


    int main()
    {
    ...
    --> while((indicator = 'y' || indicator = 'Y') && count<=max)
    ...
    }

    the arrow isnt part of the code

    any help on this error would be helpfull

    thanx

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    you should be using == not =.
    the = is the assignment operator you need the equality operator ==
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    you want this:

    while( (indicator == 'y' || indicator == 'Y') && count<=max )

    = is an assignment operator.
    == is an equality operator.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  4. #4
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    doh! If ya dont type fast enough around here.... Ah, well.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    224
    dam im stupid how could i miss that
    thanx anyways

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    224
    ok now i got it working but its outputting differently than i want it to and its giving me negative numbers


    Code:
    #include <iostream.h>	//include the header file
    #include <iomanip.h>
    ////////////////////////////
    //                              //		
    // the mian function	//	
    //                              //
    ////////////////////////////
    
    int main()
    {
    	const int max =20;	//the heighest you can count to
    	double gas[ max ];	//the amount of gas (cant be enterd more than MAX times)
    	long miles[ max ];	//the amount of miles (cant be entered more than MAX times)
    	char indicator = 'y';	//for checking yes no questions
    	int count = 0;	// for various counting procedures
    
    	while((indicator == 'y' || indicator == 'Y') && count<=max)	//get the info for the miles and gas
    	{
    		cout<<endl;
    		cout<<"please enter the odometer count:";	//ask for the miles before driving
    		cin>>miles[count];	//get the miles
    
    		cout<<endl;
    		cout<<"please enter the gas count:";	//ask for the gas before driving
    		cin>>gas[count];	//get the gas befor driving
    		count++;
    
    		cout<<"do you want to enter again?:";	//ask if they want to enter the values after driving
    		cin>>indicator;	//test to see what they choose
    	}
    
    	if(count<=1)	//if they chose the count will be 1 or less so if it is you 
    		{			//cant test the value 
    			cout<<endl;
    			cout<<"sorry you need to enter at least 2!";  //tell them what they need
    			return 0;	//end the program
    		}
    
    	for(int i=1; i<count; i++);	//set a for loop
    		cout<<endl
    			<<setw(2)<<i<<"."
    			<<" gas purchesed= "<<gas[i]<<"gallons, " //tell them howmuch gas they purchased
    			
    			<<"resulted in, \n"
    			<<(miles[i] - miles[i-1] / gas[i])	//tell them the efficiency of there car 
    			<<"miles per gallon";
    		cout<<endl;
    		return 0;    //end the program
    }

    any help will be appreciated
    Last edited by c++.prog.newbie; 12-09-2001 at 06:41 PM.

  7. #7
    Registered User
    Join Date
    Nov 2001
    Posts
    53
    Hmm... Not sure what you're trying to do exactly (what the heck is an odometer??) but...

    1) for loops need a { and a } unless it's only the next line for the loop in which case you need nothing at all at the end of the line.

    2) 'count' is not incremented in your while-loop

    3) 'count' starts at 1 instead of 0 in the for-loop mentioned in point 1)

    ie.

    Code:
    while(.....) {
       ....
       ....
       count++;    // increment count in your while-loop
    }
    
    for(....=0;...;...) {            // Start count off at 0 in your for-loop
       ....
       ....
       ....
    }          // Use braces in your for-loop

    Almosthere
    "Technology has merely provided us with a more efficient means for going backwards" - Aldous Huxley

  8. #8
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> for(int i=1; i<count; i++);

    That is a classic gotcha! The ";" completes the for loop, therefore you are incrementing i happily, but doing absolutely nothing else. almost_here has given you the syntax.

    almost_here:

    The odometer is the device, usually part of the speedo assembly, which logs how far you've gone.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  9. #9
    Registered User
    Join Date
    Nov 2001
    Posts
    53
    almost_here:

    The odometer is the device, usually part of the speedo assembly, which logs how far you've gone.
    Thanks ... you learn something new every day don't you?
    "Technology has merely provided us with a more efficient means for going backwards" - Aldous Huxley

  10. #10
    Registered User
    Join Date
    Oct 2001
    Posts
    224
    ok
    thanx

    what i was trying to do was to get it to display the car miles per gallon

    the reason i had it (i) start at 1 is because it displays the number of times you bought gass and you cant buy gas 0 time and still get the gas milage


    and one more thing what does this mean

    8.85995e+006
    Last edited by c++.prog.newbie; 12-10-2001 at 04:15 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21