this is my code
Code:
#include <iostream>
#include <cmath>
using namespace std;
float number1()//the function that gets the first number
{
float x;
cout<<"please enter a number:";
cin>> x;//this is where the number is stored
return x;//the value of x is now "float number1()"
}
char operation()
{
char a;
cout<<"please enter a operation (x, / , - , +, ^, s(square root for first number))";
cin>> a;
return a;
}
float number2()
{
float y;
cout<<"please enter another number:";
cin>> y;
return y;
}
float math()
{
float x = number1();//saying the variable x is the function "float number1()"
char a = operation();
float y = number2();
float answer;
float answer2;
//this next part decides if you add, multiply, divide, or subtract depending on the input
switch(a)
{
case 'x':
answer = x*y;
break;
case '/':
answer = x/y;
break;
case '+':
answer = x+y;
break;
case '-':
answer = x-y;
break;
case '^'://pow is power (like 1 to the tenth power)
answer = pow (x,y);
break;
case 's'://sqrt is square root
answer = sqrt (x);
break;
}
return answer;
}
int main()
{
float answer = math();
char enter;
cout<< answer <<"\n";
system("pause");
cin.get();
}
so i would like to know how to not do float number 2 when the operation is square root.