How to Code this ?

How to Code this?

Let's suppose we have a BASE & POWER and user have to enter BASE and POWER, After he enter that, the BASE will be Multiply using Loop to multiply with it's power,
after that we'll use do while loop for the cout of The Answer is?

Do anyone can help with this coding?

BASE = 5
POWER = 3

cout << "Enter Base= ";
cin >> b;
cout << "Enter Power= ";
cin >> p;
for(i=1; i=<p; i++)
{
ans = a x b

etc........
..........
....


while {
cout << "The Answer is= "


Something like that I can't complete this please help


Try to correct this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>

using namespace std;

int main()

{
int a, b , c;
int d=1;
char e;
do 
{
cout<<"enter base : ";
cin>>a;
cout<<"enter power : ";
cin>>b;
for (c=1;c<=b;c++)
{
    d=d*a;
cout<<"the answer ="<<d;
}

}
cout<<"Enter n to exit or others to continue";
cin>>e;
    while(e!='n')
}
Last edited on
You could just use pow().
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
int x, n, result;
cin >> x; 
cin >> n; 
result = pow(x, n); //x^n
cout << endl << result;
}

Unless you NEED to do it otherwise?
I wanna complete it using Do while loop that one you said that is simple....

Please change few coding for this....

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;
void main()
{
	char ch;
	do
	{
		int x, y, z;
		int a = 1;
		cout << "Enter the Value of Base: ";
		cin >> x;
		cout << "Enter the Value of Power: ";
		cin >> y;
		for (z = 1; z <= y; z++)
		{
			a = a*x;
		}
		cout << "Your Answer= " << a << endl;
		cout << "Do you want to Continue? y/n:";
		cin >> ch;
	} while (ch != 'n');
	
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
	char ch;
	do
	{
		int x, y, a;
		cout << "Enter the Value of Base: ";
		cin >> x;
		cout << "Enter the Value of Power: ";
		cin >> y;
                a = pow(x, y);
		cout << "Your Answer= " << a << endl;
		cout << "Do you want to Continue? y/n:";
		cin >> ch;
	} while (ch != 'n');
}
Last edited on
Topic archived. No new replies allowed.