Write a program using loop that has the user enter two numbers and then power them w.o power function

Write a program that has the user enter two numbers and then calculates and displays results
the 1st # raised to the 2nd #
the 1st # raised to the 1st #
the 2nd # raised to the 1st #
the 2nd # raised to the 2nd #
NOTE: Use a loop NOT the “pow” function to do this!

This is what I have so far. It's only right when I enter 2 different number like 2 and 3. But when I enter 2 same number. The answer is screw up.

#include <iostream>
using namespace std;
int main (){
//declare variables local to main
int num1,num2,count,count2,count3,count4;
//get user input
cout<<" Please enter two numbers"<<endl;
cin>>num1>>num2;
count = 1;
for (int i = 1; i<= num2; i++){
count = num1 * count;
count2 = num1 * num1;
count3 = num2 * count;
count4 = num2 * num2;}
cout<<num1<<'^'<<num2<<'='<<count<<endl;
cout<<num1<<'^'<<num1<<'='<<count2<<endl;
cout<<num2<<'^'<<num1<<'='<<count3<<endl;
cout<<num2<<'^'<<num2<<'='<<count4<<endl;

return 0;
}
Last edited on
Here it is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;

int main(){
int base;
int exp;
int res = 1;
int i;
cout<<"Please enter the base: "<<endl;
cin>>base;
cout<<"Please enter the exponent: "<<endl;
cin>>exp;
for (i = 0; i<exp; i++)
res *= base
cout<<"The result is: "<<res<<endl;
system("PAUSE");
return 0;
}
Topic archived. No new replies allowed.