Here is the code modified with test statements for the scans and test statements for input of power as 0. When I input power as 0, total comes out as 0.000. This is odd because the statement total = 1 immediately precedes the output statement.
Otherwise, if power is input as a positive number, the output for total = -2.000.
Code:
#include <stdio.h>
int main(void){
int x, power;
long double number, placeholder, total;
// The above were previously long long int, and the code worked.
// The below portion the user inputs a number, and an exponent value.
printf("calculate the exponential value of a number::\n\nenter a number: ");
scanf("%Lf", &number);
//test statement 1 works
printf("\ntest for first input: %Lf\n", number);
printf("enter the value of the exponent (value must not be negative): ");
scanf("%d", &power);
//test statement 2 works
printf("\ntest for second input: %d", power);
// This loop just checks whether the power is negative, inwhich case it terminates
if (power < 0){
printf("improper exponent value\nprocess terminated");
return 0;
}
// The below is just my way of dealing with a 0 power
else if (power == 0){
total = 1;
// Test statement 3. Total was just set to 1; this should output 1.000. But it outputs 0.000
printf("\n\ntest for when input of power = 0: %Lf\n\n", total);
}
// Here is where the real loop calculations take place. It is just looping to calculate the power
// of a number, uses a placeholder to recalculate and then dumps that out at the end.
else {
placeholder = number;
x = 1;
while (x < power){
placeholder = placeholder * number;
x++;
}
total = placeholder;
}
printf("\ntotal = %.3Lf", total);
return 0;
}