# Quick Question

This is a discussion on Quick Question within the C++ Programming forums, part of the General Programming Boards category; So I'm programming another calculator, and this time I'm trying to do exponents (ex. 3^4=81). Code: #include <iostream> using namespace ...

1. ## Quick Question

So I'm programming another calculator, and this time I'm trying to do exponents (ex. 3^4=81).
Code:
```#include <iostream>
using namespace std;
int main ()
{
int w=1;
do {
cout << "\nEnter an expression.\n"; //instructions for the user
cout << "Key: \n";
cout << "* = multiply\n";
cout << "/ = divide\n";
cout << "- = subtract\n";
cout << "^ = x to the yth power\n";
int x,z;
char y;
cin >> x >> y >> z; //get the expression
switch (y) {
cout << "The answer is " << x+z << ".\n";
break;
case '-':
cout << "The answer is " << x-z << ".\n";
break;
case '*':
cout << "The answer is " << x*z << ".\n";
break;
case '/':
cout << "The answer is " << x/z << ".\n";
case '^':
for (z; z >= 2; z=z-1)
{
int Q;
Q=x*x;
}
cout << "The answer is " << x << ".\n";
break;
default :
cout << "The expression is invalid.\n";
break;
}
cout << "To run function again, press 1.  Otherwise, press 0.\n"; //Optional Continuation
cin >> w;
} while (w==1);
cin.get();
}```
This program runs fine, but when I try to do the exponent, I get the wrong number. Usually it happens like this:
3^4 = 3
6^2 = 6
etc.
So basically I just get my x value back. How do I fix this?
Thanks

2. Notice that you don't change x in that part of the program, so the value of x remains the same.