# Thread: Exponent If and Else Statements

1. ## Exponent If and Else Statements

Okay so I am programming and my tutor told me to fix my program about exponents and computing exponents. My program will only tell the answers when the exponent is 0 or greater than one. Whenever I enter 1 as my exponent it will tell me the answer to the equation is 1 instead of the base number. I was wondering if someone could help me with this. Here is my code:
insert
Code:
```#include <stdio.h>
#include "genlib.h"
#include "simpio.h"
/* This program computes the power of a number */
main()
{
int base,exponent,counter,i;
printf("This program computes the power of a number using multiplication.\n");
base = GetInteger();
counter = base;
i = 0;
exponent = GetInteger();
if(exponent>1)
{

while(i<exponent){
base = base*counter;
i = i + 2;
}
}
else if (exponent>=0){
base = 1;
}
else if (exponent >= 1)
{
base = counter;
}
else
{
printf("There is a bug in this program.");
}

printf("%d to the power of %d is:%d.",counter,exponent,base);
}```
Now I don't know what is wrong with this but if someone could help me that would be great!

2. The first thing is indent code properly so you (and everyone else) can see the program flow at a glance.
Code:
```#include <stdio.h>
#include "genlib.h"
#include "simpio.h"
/* This program computes the power of a number */
main()
{
int base, exponent, counter, i;
printf("This program computes the power of a number using multiplication.\n");
base = GetInteger();
counter = base;
i = 0;
exponent = GetInteger();
if (exponent > 1) {
while (i < exponent) {
base = base * counter;
i = i + 2;
}
} else if (exponent >= 0) {
base = 1;
} else if (exponent >= 1) {
base = counter;
} else {
printf("There is a bug in this program.");
}

printf("%d to the power of %d is:%d.", counter, exponent, base);
}```
Next, better variable names would help.
I mean, you basically reuse 'base' as the result, and store the original value in 'counter'.

Wouldn't it be better to just leave the base variable alone, and have another variable called 'result'
So you have
result = 0 // for exponent = 0
result = base // for exponent = 1
etc