Please Help! Thank You XOXO

I have a project due some time next week and I really need help. I have a feeling I am not too far away from being finished but I am not sure. I am completely new at the whole programming thing and it is actually a pretty easy program from what I understand. I need to link the other functions to give me the correct result but idk how to do that ...This is what I have so far

int main ()
{
const int exit_out= 9;
result=0;

cout <<"****Welcome To My Calculator****"<< endl << endl;
cout<<"Select One Of The Following Operations:"<<endl;
cout<<"\t 1.Square Root"<<endl;
cout<<"\t 2.Cube"<<endl;
cout<<"\t 3.Natural Logarithm"<<endl;
cout<<"\t 4.Inverse"<<endl;
cout<<"\t 9.Absolute Value"<<endl<<endl;
cout<<" "<<"Enter selection now: ";
cin>> selc;
cout<<endl;
cout<<"Enter Desired Number: ";
cin>>n1;
do
{
switch (selc)
{
case 1: result = square;
break;
case 2: result = cube;
break;
case 3: result = natural_log;
break;
case 4: result = inverse;
break;
case 5: result = absval;
break;
default: cout<<"Invalid selection, please try again."<<endl;
break;
}

}

while (selc != exit_out);

cout << "The Result is" << result << endl;

return 0;
}

double sqrt( double x )
{
return sqrt(n1);
}

double pow( double base, int exponent)
{
return pow(3, n1);

}

double log(double x)
{
return log(n1);

}

double inv ( double x)
{
return 1/n1;

}

double fabs (double x)
{
return fabs(n1);

}
This:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
switch (selc)
{
case 1: result = square;
    break;
case 2: result = cube;
    break;
case 3: result = natural_log;
    break;
case 4: result = inverse;
    break;
case 5: result = absval;
    break;
default: cout<<"Invalid selection, please try again."<<endl;
    break;
}


should be:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
switch (selc)
{
case 1: result = sqrt(n1);
    break;
case 2: result = pow(n1, 3);
    break;
case 3: result = log(n1);
    break;
case 4: result = inv(n1);
    break;
case 5: result = fabs(n1);
    break;
default: cout<<"Invalid selection, please try again."<<endl;
    break;
}


You don't need to provide your own functions.

You need to declare n1 somewhere suitable using a suitable type.
You need to declare your functions before they are called, so the compiler knows what they are. Also, your calling them wrong. I suggest you read up on functions::

http://cplusplus.com/doc/tutorial/functions/
http://cplusplus.com/doc/tutorial/functions2/
Topic archived. No new replies allowed.