### Calculator

I'm trying to create a calculator that will store a memory function that I can recall. I can get it to store, but I'm not sure how to get the program to loop back to the beginning so I can run the recall function (getmemorynumber) and run through another calculation. Is there a way to return to the start of main by writing that into the class functions?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115`` ``````#include using namespace std; class Calculator { //private properties to protect data private: float answer; float memory; //public properties to allow input and access to private properties public: float Add(float, float); float Subtract(float, float); float Multiply(float, float); float Divide(float, float); float GetAnswer(); float GetMemoryNumber(); void SetMemoryNumber(float); }; //functions declared: float Calculator::GetAnswer() { return answer; main(); } float Calculator::GetMemoryNumber() { return memory; } //set memory to be able to integrate in calculations void Calculator::SetMemoryNumber(float x) { memory = x; } //addition function float Calculator::Add(float x, float y) { answer = (x+y); } //subtraction function float Calculator::Subtract(float x,float y) { answer = (x-y); } //multiplication function float Calculator::Multiply(float x,float y) { answer = (x*y); } //division function float Calculator::Divide(float x,float y) { answer = (x/y); } int main() { Calculator calc; float x; float y; string op; string func; cout <<"\n*Possible operations are: (+, -, *, / mem, clearmem, prime)*\n" << endl; cout <<"Please enter function: " << endl; cin >> op; if (op == "mem") { cout << "\nMEM = " << calc.GetMemoryNumber() << endl; cout << "\nEnter operation then second number or q to quit:\n"; cin >> op >> y; } else if (op == "setmem") { cout << "\nEnter MEM = "; cin >> x; calc.SetMemoryNumber(x); cout << "MEM set to: " << calc.GetMemoryNumber() <> op >> y; } if (op == "+") { calc.Add(x,y); cout << "\nAnswer = " << calc.GetAnswer() << endl; } else if (op == "-") { calc.Subtract(x,y); cout << "\nAnswer = " << calc.GetAnswer() << endl; } else if (op == "*") { calc.Multiply(x,y); cout << "\nAnswer = " << calc.GetAnswer() << endl; } else if (op == "/") { calc.Divide(x,y); cout << "\nAnswer = " << calc.GetAnswer() << endl; } return 0; }``````
Also, am I making this more complicated than it needs to be?
Topic archived. No new replies allowed.