c++ polynomial

HI!
i need help with this simple code!!!
i don't know what's wrong but i guess it's in the ReadPoly
it's for reading two poly and summing and multiplying them

this is the code :


#include <iostream>
using namespace std;
struct spoly
{
int val;
int power;
spoly *next;
};
spoly poly;
void insertion (spoly *&LS,spoly ele)
{
spoly *temp,*NI,*PI;
temp = new spoly;
temp->power =ele.power;
temp->val =ele.val;
temp->next=NULL;

if (LS ==NULL)
LS=temp;

else
{
NI=LS;
bool Located =false;

while (NI!=NULL && !Located)
{
if (NI->power > ele.power)
{
PI=NI;
NI=NI->next;
}
else
Located=true;
}

if (NI!=NULL && NI->power == ele.power)
NI->val=NI->val + ele.val;
else
{
temp->next=NI;
if( NI==LS)
LS=temp;
else
PI->next=temp;
}
}
}



void ReadPoly (spoly *&LS)
{
char Choice;
Choice='Y';
while ( Choice=='y'|| Choice=='Y')
{
cout <<"X power =";
cin>> poly.power;
cout<< "X value =";
cin >> poly.val;
if (poly.val!=0 )
insertion(LS,poly);
cout<<"******Do you want to add more items? (Y/N)****"<<endl;
cin>>Choice;
}

}





void WritePoly (spoly *LS)
{
spoly *temp =LS;

while (temp!=NULL)
{
if (temp!=LS ||temp->val > 0)
cout<<'+';
cout<<temp->val;

if (temp->power != 0)
{
cout<<"x";
if (temp->power !=1)
cout <<'^'<<temp->power;
}
temp=temp->next;
}
cout<<'\n';

}


void AddPoly (spoly *LS1,spoly *LS2,spoly *&LS3)
{
spoly *temp=NULL;
temp =new spoly;

temp=LS1;
while (temp!=NULL)
{
insertion(LS3,poly);
temp=temp->next;
}

temp=LS2;
while (temp != NULL)
{
insertion(LS3,poly);
temp=temp->next;
}
}

void MultPoly(spoly *LS1,spoly *LS2,spoly *&LS3)
{
spoly *temp1;
spoly *temp2;
spoly ele;

temp1=LS1;
while (temp1 != NULL)
{
temp2=LS2;
while (temp2!=NULL)
{
ele.val = temp1->val * temp2->val;
ele.power= temp1->power + temp2->power;
insertion(LS3,ele);
temp2=temp2->next;
}

temp1=temp1->next;
}
}
void main ()
{
cout<<"******************Welcome To The Program*****************"<<endl;
spoly *ls1=NULL;
ls1= new spoly;
spoly *ls2=NULL;
ls2= new spoly;
spoly *ls3=NULL;
ls3= new spoly;


cout<<"Enter First Poly"<<endl;
ReadPoly(ls1);
cout<<"POLY1=";
WritePoly(ls1);

cout<<"Enter Secound Poly";
ReadPoly(ls2);
cout<<"POLY2=";
WritePoly(ls2);




AddPoly(ls1,ls2,ls3);
cout<<"POLY1+POLY2=";
WritePoly(ls3);

MultPoly(ls1,ls2,ls3);
cout<<"POLY1*POLY2=";
WritePoly(ls3);




}




thanks for helping :)
Topic archived. No new replies allowed.