Search: | |||||

| ||||

Home » Forum » C++ Programming | RSS Feeds |

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:

[output]

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

[/output]

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 << "+";

}

cin.get();

cin.get();

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()

{

getpolynomial();

}

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

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

Related Topics:

- Echoing non-ASCII chars in dos
- how do i get user input?
- help with making macro with user input
- How to store user input in a worksheet?
- How to control number of textboxes according to user input
- User input in creating a Excel Workbook
- Need to delete a row in excel based on user input
- re-directing pivotcache based on user input
- Message box with user input
- User Input
- Program to count length of user input string in Assembly
- Taking input from user and printing stars
- Cursor as an input Parameter to SP
- farsi input
- name was started with an invalid character Cannot view XML input using XSL style sheet
- Retrieve values when getting xml as a input parameter in a stored procedures
- Problem in Date input from JSP page
- Formated input into JTextField
- INPUT AND OUTPUT PROGRAM
- Password input from System.in
- jsp receiving an input type file
- java Input
- input /output problem
- String input
- Need to convert an integer input to a text output