This is my second attempt at a calculator, but my first at switch statements. I try to compile this, but i get a bulk of errors that make no sense to me, they all look rather similar, here is an example of the error: error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Elem> &' from 'std::istream'. I have a feeling that I may have messed up in many, many places in this code, so I can understand if it is to time consuming to help me. All help is greatly appriciated! :-)
#include <iostream>
using namespace std;
int main()
{
int x, y, z;
char math_operator, exit_app;
int startover(char& exit_app);
int calculation(int x, int y, int& z, char math_operator);
cout << "(x ? y) - Please your first number followed by a space, then a legal math operator, followed by a space, then your second number. - (x ? y): ";
cin >> x >> math_operator >> y;
while ((math_operator = '/') && (y == 0))
{
cout << "Error: Cannot divide by zero." << endl;
cout << "Please re enter a legal math operator ( Supported: Addition(+), Subtraction(-), Multiplication(*), Divide(/) ): ";
cin << math_operator;
}
while ((math_operator != '+') (math_operator != '-') (math_operator != '*') (math_operator != '/'))
{
cout << "You have not entered a supported math operator." << endl;
cout << "Please enter a legal math operator: ";
cin >> math_operator;
}
calculation(x, y, z, math_operator);
cout << x << " " << math_operator << " " << y << " = " << z << endl;
startover(exit_app);
}
int calculation(int x, int y, int& z, char math_operator)
{
switch (math_operator)
{
case '+': z = x + y; break;
case '-': z = x - y; break;
case '*': z = x * y; break;
case '/': z = x / y; break;
}
return z;
}
int startover(char& exit_app)
{
cout << "Thank you for using my program!" << endl;
cout << "Would you like to start over? ( s = start over, q = quit ): ";
cin >> exit_app;
switch (exit_app)
{
case 's': main()
case 'q': cout << "Have a nice day!" << endl;
}
cin.get()
}