#include using namespace std; /* Write a polynomial evaluator that works like this: Enter value for x: 3.1 Enter polynomial to be evaluated (e.g. 3.1*x^2 - 2.0*x^1 + 1.1*x^0 = ) 0.75*x^5 - 1.8*x^3 + 0.3*x^2 + 1.1*x^1 = Result is 167.388 */ int main77() { // Read in the value for x double x; cout << "Enter value for x: "; cin >> x; /* * Get and evaluate the polynomial */ // Prompt and initialize cout << "Enter polynomial to be evaluated (e.g. 3.1*x^2 - 2.0*x^1 + 1.1*x^0 = )" << endl; double sum = 0; char op = '+'; while ( op != '=' ) { /* * Get c x^n term */ // Get inputs double c; int n; char junk; cin >> c >> junk >> junk >> junk >> n; // Compute x^n double term = 1; for (int i=0; i < n; i++) { term = term * x; } // Multiply by c term = term * c; // Add into total if (op == '+') { sum = sum + term; } else { sum = sum - term; } // Get the next operator cin >> op; } // Output result cout << "Result is: " << sum << endl; return 0; }