User Profile
Collapse
-
Try making the base 0 and it returns a garbage value for the sign function. -
Program HELP with Sign Function
I have a program that works fine but when I put in a zero the sign is supposed to return zero but doesn't
Code:#include <iostream.h> #include <stdlib.h> //////////////////////////////////////////////// //Power Function int power(int,int); int power(int base,int exp) { int sum=1; for (int i = 0; i < exp; i++) { sum=
-
-
Loop Question
I need a loop that can be put in 3 instances. I am not sure which loop I can find and I dont want to use a switch statement so can you help? I Already know the code just the loop for it.
Basically I want to
if (blabla)
{ then do this};
if (blabla2)
{ then do this};
if (blabla3)
{then do this}; -
Code:for (int i = 0; i < exp; i++); { sum= base*sum; } return sum; }
Last edited by sicarie; Apr 5 '07, 01:38 PM. Reason: Full code removed per FAQ, and please use [code] and [/code] tags.Leave a comment:
-
Code:for (int i = 0; i < exp; i++); { sum= base*sum; return sum; }
Last edited by sicarie; Apr 5 '07, 04:19 AM. Reason: Please use [code] and [/code] tags around your code.Leave a comment:
-
-
ahh ok I dont know why but that works so here is the thing
I input 5
then input 2
it says that the answer is 5
cout<<sum...Leave a comment:
-
I get one error when I try to run it says parse error and points to
for (int i = 0; i < exp; i++; )...Leave a comment:
-
hmmm like
for( i=0; i<exponent; i++; sum=1 )
{
sum= base* sum
}
then base which is the base will be multiplyed by the sum which os one but when the loop comes back around wont the sum be 1 again? This doesnt make sense to me.Leave a comment:
-
ok I am seeing the working but I still dont get how you will declare the sum = 1
And in the loop the sum will have a new value but when the loop, loops, I beleive the sum will become 1 again....Leave a comment:
-
-
-
well in your example n should start out with sum =1 but doesnt the sum = 1 restart the sum = sum * base when it loops?...Leave a comment:
-
-
well you want the base * base so would sum = base * base work I dont think so because then I think the sum with then need to be multiplyed by the base? Am I making things more complex?...Leave a comment:
-
-
x^5 and using that method "variable += 1"confuses the crap out of me I rather just use the straight out one....Leave a comment:
-
the loop ends when the counter becomes less then the exponent. I was thinking that base=base*base but I knew that wouldnt work so I need a third variable I think to store the original base in and then multiply it by the base untill the loop ends...Leave a comment:
-
No activity results to display
Show More
Leave a comment: