|
From: Alan T. <ala...@3n...> - 2001-01-06 23:05:02
|
Scone,
Your syntax for the "for" loops is wrong. For example,
instead of
for(u=1;u++;u<=((s/2)+1))
you should have written
for(u=1; u<=((s/2)+1);u++)
This is causing you to write past the end of the array "a", resulting in an
illegal operation. --- Alan
From: "Scone Scone" <sc...@ho...>
Date: Sat, 06 Jan 2001 18:54:51 +0100
Subject: [Dev-C++] Program causes error
Program causes errorThe program below causes an error on my computer, but I
don't know what it
could be.
Does anyone know?
Thanks, Scone
============================
#include <iostream>
#include <stdlib.h>
int main ()
{
cout << "This program reads a number and calculates all rows of two or
more\n";
cout << "successive numbers of which the sum equals this number.\n";
cout << "E.g.: 15 = 1+2+3+4+5 = 4+5+6 = 7+8\n\n";
unsigned s, t, u, x, y, z;
cout << "Type a random number and press enter: ";
cin >> s;
cout << endl;
unsigned a[(s/2)+1];
for(x=1;x++;x<=((s/2)+1))
{ y=1;
for(u=1;u++;u<=((s/2)+1))
{ a[u]=0;
}
u=x;
while(1)
{ a[y++]=u++;
t=0;
for(z=1;z++;z<=y)
{ t+=a[z];
}
if (t<=s) break;
}
cout << s << " = ";
for(u=1;u++;u<=((s/2)+1))
{ cout << a[u] << " + ";
}
cout << endl;
}
system("pause");
return 0;
}
|