base ^ exponent

I want to be able to display (BASE ^exponent = answer) 10 times. I want to increment the exponent each time through the loop as well and get a new answer. What am I doing wrong in this code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main()
{
	int base;
	int exponent;
	cout << "Please enter a base:\n";
	cin >> base;
	cout << "Please enter a exponent:\n";
	cin >> exponent;

	for(int count = 0; count < 10; count++){
		cout << base << "^" << exponent << " = " << pow(base,exponent) << endl;
			exponent++;
	}
}
I'm not sure what you mean. What is the code actually doing, and what do you want it to do? It looks like you should get something like:

20^10 = ~
20^11 = ~
20^12 = ~
20^13 = ~
...
20^20 = ~
I can not even compile your program without receiving an error for the pow function on line 17. I changed the types to float, and it worked flawlessly.
http://cplusplus.com/reference/clibrary/cmath/pow/
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
	double base;
	int exponent;
	cout << "Please enter a base: ";
	cin >> base;
	cout << "Please enter a exponent: ";
	cin >> exponent;

	for(int count = 0; count < 10; count++){
		cout << base << "^" << exponent << " = "
		<< pow(base,exponent) << endl;
		exponent++;
	}
	return 0;
}
Please enter a base: 2
Please enter a exponent: 0
2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16
2^5 = 32
2^6 = 64
2^7 = 128
2^8 = 256
2^9 = 512
Last edited on
So all I had were the data types wrong? Thanks for the help, much appreciated.
Topic archived. No new replies allowed.