// Mr. Minich
// CMPSC 101
// Ch. 3 Demo Program #5
// October 17, 2001
// Purpose - to illustrate a rounding function
#include <iostream>
#include <cstdlib> // for rand and srand functions
using namespace std;
int power(int myBase, int myExponent);
void printName();
int getRandom();
int main()
{
int base = 0; // base for the exponentiation problem
int exponent = 0; // exponent for the exponentiation problem
int result = 0; // result of the exponentiation problem
printName();
cout << "Enter a base: ";
cin >> base;
cout << "Enter an exponent: ";
cin >> exponent;
result = power(base, exponent); // two arguments are being passed to
// the function power
cout << "The result is " << result << endl;
cout << getRandom() << " is a pseudorandom integer that was generated by the computer." << endl;
return 0;
}// end of main
int power(int myBase, int myExponent)
{
int i = 0; // local loop variable
int finalAnswer = 1; // answer to exponentiation problem
for (i = 1; i <= myExponent; i++)
{
finalAnswer = finalAnswer * myBase;
}
return finalAnswer;
}// end of power
void printName()
{
cout << "Mr. Minich" << endl;
}// end of printName
int getRandom()
{
int randomInteger = 0; // a pseudorandom integer
srand(1); // seeding rand function
randomInteger = rand();
return randomInteger;
}// end of getRandom