Simple Integration Program

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 //C++ Program
//Simple Integration

#include <iostream>
#include <math.h>

using namespace std;

int main()
{   
         long int 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;
    
    
}
Shouldn't be constant=constant/power; and you might want to make power and constant floats or leave the answer as a fraction.
Yes, that'll fix it. I've got it working now. Thanks.
Topic archived. No new replies allowed.