Hello everyone, I am new to this forum and programming in general and had a quick question.
In the code below, I was wondering why it was necessary to initialize the variables. I understand the general purpose of initialization(no garbage data) but I don't see what the point is here because we declare the variable and we ask the user to tell us what the variable represents before we ever use the variable.
#include <stdio.h>
int main(void)
{
int base, power, index;
long answer;
base = 0;
power = 0;
answer = 1.00;
printf("Enter a base number: ");
scanf("%d", &base);
printf("Enter a power to raise the base to: ");
scanf("%d", &power);
for(index = 1; index <= power; index++)
answer = answer * base;
printf("%d raised to the power of %d is %ld.", base, power, answer);
getchar();
getchar();
return 0;
}