Hi, I'm trying to write a piece of code, but am having a problem using counter, and I have no idea what's going on! (The code's not finished yet, but it should be able to run as a program regardless). I'm getting "Parse issue" "expected expression error" for all of the else if (counter = __) lines. Please help! What am I doing wrong?
Alright, thanks a lot for that part it worked, but it's still printing 0 when I call my array to print, so it's not assigning each new coefficient/exponent to the array. I also moved the for statement to main. How do I manipulate the code to make sure that the array is actually being assigned? Does this have to do with what you mentioned early in your post?
Then I won't point out that you're not using comparisons in the if expressions
counter = 1 is an assignment. Of course, your compiler told you this at first, but then you surrounded it with parentheses to suppress the warning. When used in an if statement it always evaluates to true.
That makes your implementation of Polynomial::set() in the snippet above effectively:
Naming a couple variables in main (coefficient and exponent) does not make them refer to the member variables of the same name in Polynomial. set() needs to have information fed to it in the form of a parameter or parameters.
You'd get equivalent behavior with this main:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Polynomial Polynomial(0, 0);
for (int i = 1; i <= 5; i++)
cout << "Input the polynomial integer coefficient: ";
cin >> garbage;
cout << "Input the polynomial integer exponenet: ";
cout << "The polynomial expression is: ";
Awesome, fixed it by adding those parameters to set (sorry about all these mistakes I'm new to C++). That said, I'm now having another issue. I added a new variable "count" to account for the if else statements, but when I print any of the array nodes, all I get is the last inputted values for coefficient and exponent. In addition, I printed my count number at the end to see if it was a problem with that, and the count prints 0 even though i have count = count++ in the program (also if the count number is equal to zero the entire time why is anything being placed into the array? The if else statements stipulates for count = 1-5 not zero). This is the changed code: