So I'm just starting out with C++, and I thought I would try to program a simple calculator. My code seems good (to me ), but when I try to run it, I get two errors:
1. It tells me "w" has not been defined, even thought I declared it in the do function
2. When I run the program, subtraction kinda works, but I get crazy answers for everything else (ex. 1 + 1 = 98)
Code:
#include <iostream>
using namespace std;
int main (int x, int y, char z)
{
do {
bool w = 1;
cout << "\nTo run program, press 1, to exit press 0\n";
cin>> w;
char Input [3];
cout << "Enter any operation.\n";
cout << "Only one digit numbers are allowed.\n";
cout << "Use * for multiplication,\n";
cout << "/ for division,\n";
cout << "+ for addition,\n";
cout << "and -for subtraction.\n";
cin>> Input;
x = Input [0];
y = Input [2];
z = Input [1];
switch (z)
{
case '+':
cout << "And the answer is " << x+y << "\n";
break;
case '-':
cout << "And the answer is " << x-y << "\n";
break;
case '*':
cout << "And the answer is " << x*y << "\n";
break;
case '/':
cout << "And the answer is " << x/y << "\n";
break;
default:
break;
}
} while (w == 1);
system ("pause");
}
No, I don't use comments.
I don't like them.
Thanks a million!