Monday, May 24, 2010

Im trying to write a program in C++ to have a number multiply itself by another number??

{


int num1,num2,result;


cout%26lt;%26lt;"enter 1st number ";


cin%26gt;%26gt;num1;


cout%26lt;%26lt;"Enter amount of times to square ";


cin%26gt;%26gt;num2;


result=func(num1,num2);


cout%26lt;%26lt;"Your answer is "%26lt;%26lt;result;


}


int func (int num1, int num2)


{


int LoopCounter,num3;





for (LoopCounter=1; LoopCounter%26lt;=num2; LoopCounter++)


{


num3=(num1*num1);


}


num3=num3;


return (num3);











}


I need to use it in this format....only when an answer is returned, it only gives me num1*num1. for instance if I put in 2 as num1 and 3 as num2...i get 4...Help!!!!

Im trying to write a program in C++ to have a number multiply itself by another number??
Instead of num3 = num1*num1 you need to set num3 to 1 and then MULTIPLY num3 * num1.





replace int LoopCounter, num3; with int LoopCounter, num3 = 1;





and replace num3=(num1*num1); with num3*=num1;


No comments:

Post a Comment