You could do with a better OOP approach.
The polynomial class should contain a vector of the coefficients arranged in their right indices.
Then overload the + operator or make a separate function to add.
Then add the polynomials as you'd add integers, using a loop!
Thank you very much for your reply. I will do exactly what you stated.
Can you explain to me why you would use vectors instead of arrays? I am not that familiar with vectors, I know that vectors are more flexible than arrays, but that's about it.
It takes care almost everything for you in case the size is unknown (here you may not know the degree of the polynomial before the user actually enters it), and may need to change to occasionally.
vectors don't need you to get much familiar with them for simple tasks.
All you need for this is
the push_back() , pop_back(), and back() functions.
Remember that you can access its elements like arrays, using the [ ] operator.
Also, a few tips:
1. Avoid global variables unless you are sure that your program requires them. (Here, none is required))
2.You need to mention public: once . After that everything you declare is public, until you put private: or protected: .
3. In this case you need to deal with the input in a better way; asking how many polynomials initially, then for each polynomial, asking the number of coefficients.