derivative calculator need help to improve

Hi, I'm working on a program that calculates derivative.I'm only doing simple derivatives now but I eventually want to move into sinosodial functions and logarithms and more complicated stuff..this is what I have so far.I would greatly appreciate any critics or suggestions...




#include <iostream>
#include <cmath>

using namespace std;

int main()
{
cout << "welcome!! please choose an options from below\n\n "<<
" 1. press (1) for derivative of constants \\ formula kx^n \n"<<
" 2. press (2) for algebraic derivative expression \\ \n (i.e : use when there is unknown (x)\n ";



char menu;
cin >> menu;
switch (menu){

case '1':{


cout << "this is derivative of constants\n";

double k,x,n,D;
cout << "inset k"<<endl;
cin >>k;
cout << "insert x"<<endl;
cin >>x;
cout << "insert n\n";
cin >> n;
D = (k*x)*pow(x,n-1);
cout << "\nthe derivative is : " << D <<endl;
}

case '2' :
{
cout << "this is derivative of unknown\n";

double k,n,D,d;
string x;
cout << "insert k \n"; cin >> k;
cout << "insert x \n"; cin >> x;
cout << "insert n\n"; cin >> n;
D = n*k;
d = (n-1);
cout << "\n the derivative is : "<< D << "(" <<x << " ^ " << d << ")";

}
}

cout << "\n\n\n";
return main ();
}
A few quick comments:
1. Use code tags when you post, so one can read your code easier, and point out errors by line number
2. For case 1, your derivative formula is incorrect, it should be k*n, not k*x
3. Why do you ask for x in case 2, when you should not use x. You should ask only for k and n and print cout << "\n the derivative is : "<< D << "(x ^ " << d << ")";
ohh yeah..I'll fix that in case 1..thanks and how do I use tag numbers..and in case 2 I used a string..so if the user inputs 'a' 'b' or anything like that other than x..it will print out according to that..I thought maybe it would be convenient...
thanks for the appreciate it...
Last edited on
Topic archived. No new replies allowed.