954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

error with

hi ppl,
i' ve done a program that calculates the result of raising a random base to a random exponent.
the problem is that this stays in a loop that never comes out, n i have to abort it.
and, its ok to put exp*=exp?? cuz, i dont know how to put it, it has to increase in one??

for (exp = 1; exp <= exponente; exp*=exp)
{
resultado = base pow exp;
}

cout << " El resultado es: " << resultado;

return 0;


thanks!!
gispe!!

gispe
Junior Poster in Training
74 posts since Jul 2008
Reputation Points: 6
Solved Threads: 0
 

exp *= exp when exp is 1 means exp *= 1; , exp = exp*1; , exp = exp; . That increment does nothing. To increase exp by 1 every iteration, do exp += 1; , if that's what you meant. Also, what is exponente? What is it set to?

CoolGamer48
Posting Pro in Training
401 posts since Jan 2008
Reputation Points: 77
Solved Threads: 40
 

exponente is the number which multiplies the base,

sorry i didnt say that!!

gispe
Junior Poster in Training
74 posts since Jul 2008
Reputation Points: 6
Solved Threads: 0
 
for ( exp = 0, resultado = 1 ; exp < exponente ; exp++ )
    resultado *= base ;
cout << " The result is: " << resultado;


Is this what you are looking for?

Prabakar
Posting Whiz
342 posts since May 2008
Reputation Points: 94
Solved Threads: 33
 

thanks a lot prabakar!!
that worked out perfectly!!

gispe
Junior Poster in Training
74 posts since Jul 2008
Reputation Points: 6
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You