The code only executes the nested while once.. why??
int main()
{
int base, expo, power;
while (base!=0 && expo!=0)
{
count = 0;
cout<<"Enter Base: ";
cin>>base;
cout<<"Enter Exponent: ";
cin>>expo;
while(count!=expo)
{
power=base*base;
count++;
}
cout<<"Power: "<<power<<endl;
}
getch();
}
//if i put base = 5 and expo = 3 , the power displayed is still 25
base*base
is the same value no matter how many times you do the calculation.
Your outer
while
loop is also defective.
base and expo are uninitialized.
You're depending on the unitialized values of base and expo to be non-zero for the body of the while statement to execute.
Please don't cross post.
http://www.cplusplus.com/forum/general/106994/
Last edited on
Tnx Guys,
got my code to work..
sorry for the Cross Post,
newbie here.