infinite loop ?

hello i have a code i can compile it. but once i run it it starts doing errors.
i think it is because an infinite loop but i dont see where.
here is code

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	int x,max,sqdiff(1);
	cin>>max;
	int * b=new int [max] ;//pointer to my values
	int * c=new int [max] ;//pointer to my values

	for (x=1;x<=max;max=max) {

	int a,z(0),i,az;
	cout<<endl;
	a=4*sqrt(float(max))+5;
	
	
	az=a;//20
	while(az>9) {
		az=az-8;z=z+1; }
	z=2*z+1;
	

	for (i=0;i<2;i++) {
		*(b+i+x-1)=1;} 
	for (i=0;i<z;i++) {
		*(b+i+2+x-1)=i+2;}
	for (i=0;i<z;i++) {
		*(b+z+i+2+x-1)=z+1;}
	for(i=0;i<1;i++) {
		*(b+z+z+i+2+x-1)=*(b+z+z+i+1)+1;} 
	for(i=0;i<=z;i++) {
		*(b+z+z+i+3+x-1)=z+2;}
	for(i=0;i<z;i++) {
		*(b+z+z+z+i+4+x-1)=z+1-i;} 


	for (i=0;i<2;i++) {
		*(c+i+x-1)=z+i;} 
	for (i=0;i<=z;i++) {
		*(c+i+2+x-1)=z+1;}
	for (i=0;i<z;i++) {
		*(c+z+i+2+x-1)=z-i;}
	for(i=0;i<1;i++) {
		*(c+z+z+i+2+x-1)=1;} 
	for(i=1;i<=z+2;i++) {
		*(c+z+z+i+2+x-1)=1+i;} 
	for(i=0;i<z+1;i++) {
		*(c+z+z+z+i+4+x-1)=z+2;} 


	
	for (i=0;i<a-1;i++) { 
		cout<<*(b+i)<<" "<<*(c+i)<<endl; 
	  }
	x=x+(sqdiff*8);
	sqdiff=sqdiff+1;
	}

	delete b;	
	delete c;
	system("pause");
    return 0;
	}
Give your variables more meaningful names than "a", that's currently the main problem with your code.
You can still stop the debugger at any point to see what your program keeps executing.

But even without knowing what your program is supposed to be doing, this looks like an infinite loop:
for (x=1;x<=max;max=max) {
And that is wrong too:
1
2
delete b;	
delete c;

You have to use delete[] to free objects allocated with new[].
In future, use std::vector when you need a dynamic array.
Last edited on
Topic archived. No new replies allowed.