Hi, I'm new to the forum but I'm a computer engineering student at an engineering school so I will probably frequent here. I'm having a problem with creating a class based calculator. Our TA wanted us to have a calculator work that based on two things: 1. The variables for the input numbers must be floats or doubles.
2. You must be able to type in the operation you want after inputting the variables with a string. I.e, "summation" for addition and "subtraction" for subtraction. I'm going to copy-paste my visual studio code, and would love if someone could look at it and tell me why I'm getting extraneous results in the console.
Code:
#include <iostream>
#include <string>
using namespace std;
class Calculator{
float firstVariable;
float secondVariable;
double result;
string option;
public:
void Summation(){
result = firstVariable + secondVariable;
cout << "Result of summation: " << result << endl;
}
void Subtraction(){
result = firstVariable - secondVariable;
cout <<"Result of subtraction: " << result << endl;
}
};
cout << "Give two values for your variables first." << endl;
cout <<"Type 'summation' for addition of variables, 'subtraction' for subtraction of variables." << endl;
The variables firstVariable and secondVariable in main are completely unrelated to and separate from the variables of the same name in class Calculator.