The calculator program will accept inputs for the 1st number, operation, and 2nd number.
I've set up the program to select the operation with conditional statements. The program does not output however.
I also tried to print out an error message for improper operation selection using xor logic.
I think the problem lies with how I'm using my variables. Any critique or advice is appreciated.
I'm new to learning C++, so I'm trying to make a simple two input calculator. I'm trying to challenge my understanding of variables and conditional statements.
void add_func();
void sub_func();
void mult_func();
void divi_func();
int main()
{
double a;
double b;
char op;
cout << "Input 1st Number:" << endl;
cin >> a;
cout << "Select Operation: (1 = +) (2 = -) (3 = *) (4 = /)" << endl;
cin >> op;
cout << "Input 2nd Number:" << endl;
cin >> b;
if(op == 1)
cout << add_func();
if(op == 2)
sub_func();
if(op == 3)
mult_func();
if(op == 4)
divi_func();
if(op != (1 ^ 2 ^ 3 ^ 4))
cout << "Invalid Operation Selected" << endl;
return 0;
}
void add_func()
{
double a;
double b;
double c;
c = a + b;
cout << a << " + " << b << " = " << c << endl;
}
I've truncated the code to include only the add function. It should be adding the numbers and printing out the result.