Menu

non-lvalue

2002-11-27
2012-09-26
  • Nobody/Anonymous

    I get the error message: 'non-lvalue in assignment' on lines
    27,34,41,48. Here is the source code:

    #include <iostream>
    #include <stdlib.h>

    int main(int argc, char *argv[])
    {
      char op;
      float a;
      float b;
      float c;

      cout<<"SimpleCalc"<<endl<<endl;
      cout<<"syntax: 1+2"<<endl;
      cout<<"Commands:"<<endl;
      cout<<"+: a+b"<<endl;
      cout<<"-: a-b"<<endl;
      cout<<"/: a/b"<<endl;
      cout<<"*: a*b"<<endl<<endl;
      cout<<"Operation>> ";  //The operation you want to preform
      cin>>op;
      cout<<"First Number>> ";
      cin>>a;
      cout<<"Second Number>> ";
      cin>>b;
     
      if(op=='+')
      {
       a+b=c;
       cout<<"Result: "<<c;
      }
      else
      {
       if(op=='-')
       {
        a-b=c;
        cout<<"Result: "<<c;
       }
       else
       {
        if(op=='/')
        {
         a/b=c;
         cout<<"Result: "<<c;
        }
        else
        {
         if(op=='*')
         {
          a*b=c;
          cout<<"Result: "<<c;
         }
        }
       }
      }
      system("PAUSE");   
      return 0;
    }

     
    • Nobody/Anonymous

      Assignment inmost computer languages goes from right to left, so I *think* what you want to write is:

      c = a + b

      This takes the value of b, adds it to a, and then assigns that result to c.

      not

      a + b = c

      The last operation, as you wrote it, assigned the value of c to b, adds that value to a, then looks for a place to put the result, which you have not given, because the operation comes to sa screeching halt after the "a"

      Wayne

       
    • Nobody/Anonymous

      Thanks.

       
    • Nobody/Anonymous

      In my best southern fired accent - "use welcome!
      We aim's to please....or kill, as the case calls"

      Wayne

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.