I'm attempting to make a simple integration program that takes an integral of a user-entered problem. It works...but partially. For example, when I enter 2x^1, the answer should be x^2, and it gets it correct. However, when I input something like 20x^4, it gets the power and variable in the right place, but outputs a 0 instead of a 4. Another example of where it gets it wrong is when I give it a problem that will have a fraction, such as, 17x^3, which should have the answer as (17/4)*x^4. (This is supposed to be only a simple integration program, I'm using the generalized equation that the integral of cx^n = (cx^(n+1))/n, where c is a constant, x is the variable, and n is the power).
//C++ Program
//Simple Integration
#include <iostream>
#include <math.h>
usingnamespace std;
int main()
{
longint constant, power;
char var;
cout << "Enter a constant of variable to be integrated (if there is no constant enter 1): " << endl;
cin >> constant;
cout << "Now enter the variable to be integrated: " << endl;
cin >> var;
cout << "Finally, enter the power which everything is raised to: " << endl;
cin >> power;
cout << "\nYou have entered: \n" << constant << "*" << var << "^" << power << "\n" << endl;
power= power + 1;
//cout << endl << endl << constant << endl;
constant=power/constant;
//cout << endl << endl << constant << endl;
cout << "The integral is: " << constant << "" << var << "^" << power << endl << endl;
system("pause");
return 0;
}