Started C programming again, but I am stuck on a relatively very simple problem. The problem is stated in the comments.
Code:
/* Programming Projects
Problem 5
Write a program that asks the user to enter the value for x and then displays the value of the following polynomial: 3x^5+2x^4-5x^3-x^2+7x-6
*/
#include <stdio.h>
int main (void)
{
float x = 0, poly = 0;
printf("Enter a value for x: ");
scanf("%f", & x);
poly = 3 * (x*x*x*x*x) + 2 * (x*x*x*x) - 5 * (x*x*x) - (x*x) + (x*x*x*x*x*x*x) - 7;
printf("Value obtained: %.4f", poly);
return 0;
}
No matter what I enter for x the value of the polynomial is -7. I realize that would only happen if the value of x = 0, but doesn't the scan function replace the value of x with the one I wish to enter?
I just realized I inputed an incorrect equation from what the problem was asking for, but it still should produce a result. Why not?