C++ Programming Forum

Ask Question   UnAnswered
Home » Forum » C++ Programming       RSS Feeds

Echo users input

  Asked By: Eugene    Date: Jan 05    Category: C++ Programming    Views: 1669

first problem:

I am writing a program that lets the user input the power and the corresponding constant coefficients of a polynomial function, then the program should output the users mathematical function.

for example:


Enter the order of the polynomial: 2

Enter the coefficient of x^2: 1

Enter the coefficient of x^1: -5

Enter the constant term: 2

Your function is f(x) = x^2-5x+2


I have my code below but I encountered a small problem. There is still "+" that will come up after the constant term. And if possible, i want to ouput the function as what is shown above.(i,i., if the power is 1, just put 'x' and if the power is 0 just put the constant coefficient.

Your function is f(x) = x^2-5x^1+2x^0+

How would i fix this?

#include <iostream>
using namespace std;

int main()
double coeff[1000];
int p;

cout << "Enter the power of the equation: ";
cin >> p;

for(int i = p; i > 0; i--)
cout << "Enter the coefficient of x^" << i << ": ";
cin >> coeff[i];

cout << "Enter the constant term: ";
cin >> coeff[0];

cout << "Your function is: f(x) = ";

for(int i = p; i >= 0; i--)
cout << coeff[i] << "x^" << i;

if(coeff[i-1] > 0) cout << "+";



return 0;


second problem:

I want to make this whole thing as a function so that i will just call it whenever i need it.

int main()



Can Somebody help me with this small struggle that i am facing right now?



No Answers Found. Be the First, To Post Answer.

Didn't find what you were looking for? Find more on Echo users input Or get search suggestion and latest updates.