Noobie at Coding

Task:
Write a function:
- exp(x,y):
- where x is positive (possibly a decimal) and y is a positive integer.
- Returns x to the y.
- The definition of x to the y: x multiplied by itself y times.
- Example: 2 to the 3 is 2*2*2.
- Example: 6 to the 1 is 6.
- Example: 12 to the 0 is 1. Anything to the 0 is 1, except 0. But you don't have to worry about 0.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;
double exp(double&x,int y)
{
	int n=1;
	for(int=k;k<=y;k++)
		n=n*x;
	return n;
}
int main()
{
	double x;
	int y;
	cout<<"Enter two numbers ";
	cin>>x>>y;
	exp(x,y);
	cout<<x<<endl;
	return 0;
}

what am i doing wrong?
Last edited on
3
4
5
6
7
8
9
double exp(double&x,int y)
{
	int n=1;
	for(int=k;k<=y;k++)
		n=n*x;
	return n;
}
1. why is x passed by reference?
2. why do you use n instead of x?
3. What do you expect "int=k" to do?
for question 3.) idk...
If you don't know what it does, then why did you write it? ;)
Topic archived. No new replies allowed.