hello there, i was hoping someone could help me figure out why my program isn't compiling.

Its a polynomial math program i put together...and with my function "MathPoly" //'d out it compiles just fine....It continually tells me that variables are undeclared and the compiler is crapping out on line 51 right were it gets to the math poly function.

here is my header file:

class polynomial
{
signed int Coeff;
signed int Coeff2;
signed int Exp;
signed int Exp2;
char Var;
char Var2;
public:

Polynomial(){};

       void SetCoeff()
       {
            cout << "enter coefficient of first number"<<endl ;
            cin >> Coeff;

       }

       void SetVar()
       {
            cout << "enter first variable" <<endl ;
            cin >> Var;
       }
       void SetExp()
       {
            cout << "enter exponent of first number" <<endl;
            cin >> Exp;
       }

       void SetCoeff2()
       {
            cout << "enter coefficient of second number"<<endl ;
            cin >> Coeff2;

       }

       void SetVar2()
       {
            cout << "enter second variable" <<endl ;
            cin >> Var2;
       }
       void SetExp2()
       {
            cout << "enter exponent of second number" <<endl;
            cin >> Exp2;
       }

       void MathPoly()
       {
          if  (strcmp (Var1, Var2) && Exp1 == Exp2)
         {
         cout << "sum is" << Coeff1 + Coeff2 << Var1 << "^" << Exp1 << endl;
         cout << "difference is" << Coeff1 - Coeff2 << Var1 << "^" << Exp1 << endl;

          else

         cout << "sum is" << Coeff1 << Var1 << "^" << Exp1 << "+" << Coeff2 << Var2 << "^" << Exp2 << endl;
         cout << "difference is" << Coeff1 << Var1 << "^" << Exp1 << "-" << Coeff2 << Var2 << "^" << Exp2 << endl;
         }
       }
};

Here is my main file

#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include "ppoly.h"

int main()
{
  polynomial poly1;
  poly1.SetCoeff();
  poly1.SetVar();
  poly1.SetExp();
  poly1.SetCoeff2();
  poly1.SetVar2();
  poly1.SetExp2();
  poly1.MathPoly();
  return 0;
}

Thank you please respond if u know what i'm doing wrong :)

Check spelling and capitalization -- line 11 of the header file (as posted above) is not the same as the class name.

sorry i didn't put code tags on that i just don't know how thank u for doing it for me :/

yeah i checked all the capitalization (odd that line 11 was capitalized it wasn't on my text over here) couldn't find a single capitalization or naming error...

it just all goes to poo on line 51 it seems am i missing something? when i do the // in front of that function i can compile the whole thing

Have u added #included<cstring> in the file which contains your class definition(ppoly.h).
you will need it for the strcmp() function which is on Line 51

Well i'm almost done I can get it to compile 99.9% the only thing i haven't been able to get to work is the string comparison line. I previously was using a boolean "&&" statement in place of the 2 if statements. but when i tested the code without the strcmp it worked...

I added in the #include <cstring> might there be something else i have to do in the if statement?

void MathPoly()
      {
        if  (strcmp (Vari, Vari2)
        if  (Expo == Expo2)
        cout << "sum is" << Coeff + Coeff2 << Vari << "^" << Expo << endl;
        cout << "difference is" << Coeff - Coeff2 << Vari << "^" << Expo << endl;
        else
        cout << "sum is" << Coeff << Vari << "^" << Expo << "+" << Coeff2 << Vari2 << "^" << Expo2 << endl;
        cout << "difference is" << Coeff << Vari << "^" << Expo << "-" << Coeff2 << Vari2 << "^" << Expo2 << endl;

I just checked " Var " and " Var2 " are both "char" types, I think you can use " == " directly for checking for equality.

Following is the signature for strcmp ->

int strcmp( const char *str1, const char *str2 );

so I don't think strcmp (Var1, Var2) will work

doh!!! it compiled thanks ...i originally had it as == too!!! i took it away from that thinking the char's couldn't be compared like that.

thanks so much i'll mark as solved do u get credit for that? or something to improve ur rep?

yep.. it does increase the "Solved Threads" count next to our names

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.