I'm a beginner in C++. In this program, I'm attempting to derive a simple mathematical problem (i.e. 3x^8 = 24x^7). I know where my problem is, but I don't know how to fix it. Near the middle of the program I attempt to display what the user has entered to no avail. How can I make the system recognize the difference between the variable that is entered, the constant, and the power which everything is raised to? (I'm using the basic idea that c*x^n = c*n*x^(n-1), where c is the constant, x is the variable, and n is the power).
//C++ Program
//Program is for finding simple derivatives (i.e. 5x^7)
#include <iostream>
#include <stdlib.h>
#include <math.h>
usingnamespace std;
int main()
{
int constant, power, ans;
char var;
cout << "Enter a constant of variable to be derived (if there is no constant enter 1): ";
cin >> constant;
cout << "Now enter the variable to be derived: ";
cin >> var;
cout << "Finally, enter the power which everything is raised to: ";
cin >> power;
cout << "\n\nYou have entered: \n" << constant*power << "\n";
//ans = constant * var ^(power - 1), pow(var, power);
//cout << "\nThe deriviation is: \n" << ans << "\n\n";
system("pause");
return 0;
}
//C++ Program
//Program is for finding simple derivatives (i.e. 5x^7)
#include <iostream>
#include <stdlib.h>
#include <math.h>
usingnamespace std;
int main()
{
int constant, power, ans;
char var;
cout << "Enter a constant of variable to be derived (if there is no constant enter 1): ";
cin >> constant;
cout << "Now enter the variable to be derived: ";
cin >> var;
cout << "Finally, enter the power which everything is raised to: ";
cin >> power;
cout << "\n\nYou have entered: \n" << constant << "*" << var << "^" << power << "\n";
ans = constant * power;
power = power - 1;
cout << "\nThe deriviation is: \n" << ans << "" << var << "^" << power << "\n\n";
system("pause");
return 0;
}