'=' function as left operand Errors?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • StrugglingStudent
    New Member
    • Mar 2010
    • 2

    '=' function as left operand Errors?

    I'm having problems finishing my program, it keeps giving me the error '=':function as left operand. And im not sure what that means. It is supposed to be a function to calculate basic car rental prices. This piece of the program is where it is telling me its wrong. Im not sure how to fix it though. Any help would be excellent.

    Code:
    switch(car_type) 
    	{ 
    		case 1: 
    			cost=29.90;
    			extra=0.29;
    			total=total(cost,days_rented,km_traveled,extra); 
    		break; 
    		case 2: 
    			cost=39.95;
    			extra=0.39;
    			total=total(cost,days_rented,km_traveled,extra); 
    		break;
    		case 3: 
    			cost=49.95;
    			extra=0.49;
    			total=total(cost,days_rented,km_traveled,extra); 
    		break; 
    		case 4: 
    			cost=59.95;
    			extra=0.59;
    			total=total(cost,days_rented,km_traveled,extra); 
    		break; 
    	}
    Last edited by Banfa; Mar 5 '10, 09:44 AM. Reason: Added code tags
  • pavunkumar
    New Member
    • Feb 2010
    • 4

    #2
    Problem in Assigning the Function return values.

    In your switch cases , you are assigning the function return values in variable . this is actually function name ( total) . Which means that you are having the same name for function and your variable (total) . That is why it is throwing the error. Change your variable name or change your function name . It will work fine.
    Last edited by pavunkumar; Mar 5 '10, 04:28 AM. Reason: Adding some statements

    Comment

    • StrugglingStudent
      New Member
      • Mar 2010
      • 2

      #3
      Thank You so much! That makes so much more sense!

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        Agreed. You probably want to remove that line from each of the statements, and put after the switch
        Code:
                    return total(cost,days_rented,km_traveled,extra);
        This assumes your current function is something like
        double total (int car_type, int days_rented, int km_traveled)
        and you have another function like:
        double total(double cost,int days_rented,int km_traveled,dou ble extra)


        edit- ah well too late.

        Comment

        Working...