#include <iostream>
#include <string>
#include <math.h>
usingnamespace std;
int addNum();
int multiNum();
int subNum();
int divNum();
int sqroot();
float powrNum();
double circCalc();
double circArea();
double circCircum();
float DegToRad();
int num1, num2;
int sum;
char userInput;
char mathOp;
double radius, area, circum, diam;
longdouble pi = 3.141592653589793238462643383279502884197169399375;
int main()
{
do
{
cout << "Please choose a Calculation you want to do: \nAddition - 1 \nMultiplication - 2 \nSubtraction - 3 \nDivison - 4 \nPower - 5 \nSquare Root - 6 " << endl;
cout << "Cirlce Calculations - 7 \nDegree to Radian - 8" << endl;
cin >> userInput;
switch(userInput)
{
case'1' : addNum();
break;
case'2' : multiNum();
break;
case'3' : subNum();
break;
case'4' : divNum();
break;
case'5' : powrNum();
break;
case'6' : sqroot();
break;
case'7' : circCalc();
break;
case'8' : DegToRad();
break;
}
cout << "\nWould you like to do another operation? (y/n)" << endl;
cin >> userInput;
}while(userInput != 'n'); //just to be awkward :D
}
double circCalc()
{
cout << "You chose circle calculations! " << endl;
cout << "What do you want to do? " << endl;
cout << "Area - 1 \nCircumfrence - 2" << endl;
cin >> userInput;
switch(userInput)
{
case'1' : circArea();
break;
case'2' : circCircum();
break;
default:
cout << "Error - Invalid Input! " << endl;
}
return circArea();
return circCircum();
}
double circArea()
{
cout << "You chose area! " << endl;
cout << "Enter the radius of your cirlce: " << endl;
cin >> radius;
area = pi * (radius * radius);
cout << "= " << area;
return area;
}
double circCircum()
{
cout << "You chose cirumfrence! " << endl;
cout << "Enter the diameter of your circle: " << endl;
circum = pi * diam;
cout << "= " << circum;
return circum;
}
(For the sake of space I've removed all my other functions)
So I made/making a scientific calculator, so I thought I would practice with some basic functions; I put the program into functions, all went well till I tested it and came to the circle calculations.
If you look at line 77 and 78, which ever function is at the top, it will output that after the current function has just been done.
This is the wrong way to ask a question.
You have to make an effort, by isolating the issue, and asking a concise question while posting only relevant code.
Anyway, you can only return a single value out of a function. Which means that you can't have multiple returns. In your case, the second return circCircum(); is ignored.
In your case, again, the solution is simple: simply store the return values of your circArea() and circCirum() in a variable, and return the variable instead.
While posting this I actually had about 3 problems I wanted to ask, but I fixed them on my own, and due to this I spent about 10 minutes trying work out the current problem. So you can't really say that I was making no effort to work out the problem without me actually saying that I made no effort. Also, I thought that it clearly shows that I was implying for help with that certain piece of code.