Ok, I wrote the following program ( just messing around ), to find the exponent of a user's number.
Here's the problem:
If I place the less-than symbol ( < ) in the 'for' loop, it works fine.
However, the second I place the less-than or equal to operator ( <= ) in it's place, the code returns some crazy numbers.
I'm using: Win XP; & Dev-C++ 4.9.9.2;
Here's the code WITH the LToET operator:
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- using std::cout;
- using std::endl;
- using std::cin;
- int main()
- {
- int x = 0;
- int y = 1;
- int exp = 0;
- int choice = 0;
- cout << "Enter the base number: ";
- cin >> x;
- cout << endl;
- cout << "Now enter the exponent you want for " << x << ": ";
- cin >> choice;
- cout << endl; // | Here it is...
- // V
- for (int index = 0; index <= choice; index++)
- {
- y *= x;
- }
- cout << x << "^" << choice << " = " << y << endl;
- return 0;
- }
between the two operators ( besides the obvious one of course 8^) ).
I appreciate any help anyone could give me. It's not a huge problem, but it is
a bit frustrating.
Thanks,
-Soneji