Assignment 1

2. Ask for the Base and Exponent and output the computed power

CPE102L
1Q1819
#include <iostream>
using namespace std;
int main()
{
 int, base, exp;
 float pow=1;
 cout<<"base: ";
 cin>>base;
 cout<<"exponent: ";
 cin>>exp;
 
 if (exp==0)
 {
  pow=1;
 }
 else if (exp<0)
 {
  int tempexp=exp*-1;
  while (tempexp>0)
  {
   pow*=base;
   tempexp=tempexp-1;
  }
  pow=1/pow;
 }
 else
 {
  int tempexp=exp;
  while (tempexp>0)
  {
   pow*=base;
   tempexp=tempexp-1;
  }
 }
 
 cout<<pow;
}