This a simple calculator program. It designed to take 3 inputs from user which are one double type number, one character and another double type number. But when it compiles and runs, it shows Enter the value 2 first instead of showing the value 1 first despite of passing the value1 parameter first in the calculateResult function in the main function. Why does it happens either? The following program doesn't show any compile error.
#include <iostream>
#include <conio.h>
double getValue1() //first value
{
std::cout << "Enter value 1: ";
double input1{ 0 };
std::cin >> input1;
return input1;
}
double getValue2() //second value
{
std::cout << "Enter value 2: ";
double input2{ 0 };
std::cin >> input2;
return input2;
}
char getMathematicalOperation()
{
std::cout << "Enter a valid symbol such as'+', or '-', or '/', or '*'\n";
char symbol{0};
std::cin >> symbol;
return symbol;
}
void calculateResult(double value_1, char symbol, double value_2)
{
if ( symbol == '+') {
std::cout << value_1 + value_2;
}
else if (symbol == '-') {
std::cout << value_1 - value_2;
}
else if (symbol == '*') {
std::cout << value_1 * value_2;
}
else if (symbol == '/') {
std::cout << value_1 / value_2;
}
else {
std::cout << "Something wrong went with your operation\n";
}
}
int main(){
calculateResult(getValue1(), getMathematicalOperation(), getValue2());
getch();
}