Code:
if (seconval < 0){
firsval = 1.0;
seconval= 1/firsval;
}
ok so this code is saying that if seconval is less than zero then firsval is equal to one and seconval is equal to a=firsval which is one. so the answer here would be 1. and then in the for loop
Code:
for(count = 0; count < seconval; count++){
powerval *= firsval;
}
count won't ever be less then 1 and it never gets entered. i know i need this condition in case the exponent(meaning seconval) is negative. to fix this i need to alter the firsval becuase a number raised to the negative exponent is really 1 divided by the number raised to the absolute value of the exponent. so would the new code be
Code:
float power_func(float firsval, int seconval){
int count;
float powerval =1.0;
if (seconval < 0){
firsval = 1/firsval;
seconval *= -1;
}
for(count = 0; count < seconval; count++){
powerval *= firsval;
}
return powerval;
}