So my project is to make a console calculator using MVC principles in C++. However, we're only allowed to input 1 argument to determine the number as well as the calculation operator (+,-,..)
I did one but it turns out wrong cause I'm not allowed to cin any new numbers in the View cause only Input in Controller is allowed. The approach I'm thinking of is take the argument in the controller -> inside the View, call Model's function to scan whether that input is a number or operation -> if it's not, return back to View and return to Controller for the next input
But somehow got stuck when user enters the + it doesn't return the sum, any suggestions? Cause if the argument given be something like (num1,num2,operation) will be easier but only (tInput) handles all the Input so I'm a bit confused.
Controller.cpp (Don't change anything)
int (main) {
CalModel* tAModel = new CalModel;
CalView* tAView = new CalView(tAModel);
cout << "Calculator: 0-9, +, or C for clear: \n";
while (true)
{
char tInput = getchar();
tAView->OnKeypress(tInput); // Only one input allowed
}
}
Example output:
Calculator: 0-9,+, or C for clear:
1
+
1
=
2
+
1
=
3