A
arnuld
i wanted to know if that's a good design style (upto the knowledge i have
gained till chpater 7):
/* C++ Primer - 4/e
*
* exercise 7.4
* STATEMENT
* write a programme to take two int paramaters and generate the
result of raising the first to the power of the second. write a
programme to call your function passing it two ints. verify the
result.
*
*/
#include <iostream>
int raise_power(int x, int y)
{
int mult = 1;
while( y )
{
mult = mult * x;
--y;
}
return mult;
}
int main()
{
int i = 2;
int j = 3;
int mult_result = 8;
std::cout << static_cast<bool>(mult_result == raise_power(i, j))
<< std::endl;
/* well, never got converted to "true", it alwasy remains 1 */
return 0;
}
gained till chpater 7):
/* C++ Primer - 4/e
*
* exercise 7.4
* STATEMENT
* write a programme to take two int paramaters and generate the
result of raising the first to the power of the second. write a
programme to call your function passing it two ints. verify the
result.
*
*/
#include <iostream>
int raise_power(int x, int y)
{
int mult = 1;
while( y )
{
mult = mult * x;
--y;
}
return mult;
}
int main()
{
int i = 2;
int j = 3;
int mult_result = 8;
std::cout << static_cast<bool>(mult_result == raise_power(i, j))
<< std::endl;
/* well, never got converted to "true", it alwasy remains 1 */
return 0;
}