Emporius
Space Core
- Joined
- Aug 20, 2007
- Messages
- 3,553
- Reaction score
- 10
Well I guess this thread goes here.
I am working on a C++ programming problem for school, and I've managed to muck it all up. The question says:
"Example 4. Write a program that finds x^y for a given base x and exponent y. (Don?t use pow function to solve this examle)."
I need to use repetition structures, and in my frustration I've managed to butcher the code.
If anyone could lend a hand it would be greatly appreciated.
PS: This is the area of main confusion:
edit: Ignore the bottom, it's just the remains of an old question
I am working on a C++ programming problem for school, and I've managed to muck it all up. The question says:
"Example 4. Write a program that finds x^y for a given base x and exponent y. (Don?t use pow function to solve this examle)."
I need to use repetition structures, and in my frustration I've managed to butcher the code.
]#include <iostream>
#include <iomanip>
using namespace std;
int main () {
int x;
int y;
int pro;
cout<<"Please enter an integer value"<<endl;
cin>>x;
cout<<"Now enter a value for the exponent"<<endl;
cin>>y;
pro=0;
x=y;
while (x<=pro)
{
pro=pro*x;
x=x*x;}
cout<<""<<endl;
cout<<"The sum of all of the numbers between 1 and is equal to:"<<endl;
cout<<pro<<endl;
cout<<""<<endl;
return 0;
}
If anyone could lend a hand it would be greatly appreciated.
PS: This is the area of main confusion:
pro=0;
x=y;
while (x<=pro)
{
pro=pro*x;
x=x*x;}
edit: Ignore the bottom, it's just the remains of an old question