Tittle.exe has stopped working

Whenever i try to build a program that needs a class that isn't void the exe file always crashes. Please help?

i am using codeblock 10.05

ex. this code would crash everytime i try to build it.

#include<iostream>
#include<math.h>

using namespace std;

long IntPower(long x, int n);

long IntPower(long x, int n){
if(pow==0){
return 1;
}
else if (pow > 0){
return x*IntPower(x,n-1);
}
}

int main(){
cout<<IntPower(1,2);
}
Last edited on
1
2
3
4
5
6
7
8
long IntPower(long x, int n){
	if(n==0){
		return 1;
	}
	else if ( n > 0){
		return x*IntPower(x,--n);
	}
}
You know what's your mistake? You called IntPower from your own IntPower function, with undefined results, so it crashed.
1
2
3
4
5
6
7
8
9
10
long IntPower(long x, int n) {
	if(n==0)
		return 1;
	else if(n>0){
		long xStart = x;
		for(int i = 0; i < n; i++)
			x = x * xStart; // You can also use "x *= xStart;"
		return x;
	}
}
That's not an error. That's called recursion.

@TC: You are trying to reference a variable called 'pow', which isn't even declared. How is this compiling?
closed account (zb0S216C)
Zhuge wrote:
You are trying to reference a variable called 'pow', which isn't even declared. How is this compiling?

He's comparing the address of std::pow( ). Notice the #include <math.h> header? It should be #include <cmath>, anyway.

Wazzak
Topic archived. No new replies allowed.