# Thread: help with simple program

1. ## help with simple program

this program im writing should take radius imputs from the user after the user selects how many circles (between 1 and 10) they would like to imput radi for. after that, it should store those radi in an array, and calculate circumference and area for each radi and print the results.

what i have so far compiles just fine however when i run the ./a file (im using cygwin) i get an error of the following:
18 [main] a 2604 _cygtls::handle_exeptions: Error while dumping state (progably corrupted stack)
Segmentation fault (core dumped)

whats goin on with the stack? how can it just corrupt like that...is it a problem whithin my program or my compiler?

Code:
```#include <stdio.h>
#define PI 3.14159265
int main (void)
{
int circleno, i;
int j;
float circumference[i];
float area[i];
circleno = i;

printf("Please enter the number of circles (max = 10):\n");
scanf("%i", &circleno);

if ( circleno > 10 )
printf("Error -> %i circles is to many. Please try again:\n", circleno );
else
for ( j = 1; j <= circleno; ++j ) {
printf("Enter the radius for circle #%i:\n", j);
}

printf("circumferences = %f\n", circumference[i]);
printf("areas = %f\n", area[i]);
}```

2. Question: does the compiler know what i is? You can't have a variable in an array during compilation, at least not in this instance. Use a number instead. You want a maximum of 10 so it'd be wise to have 10 here. Instead of %i, you'd want %d, for the string. %d is for displaying integers.

3. Code:
```	int circleno, i;
int j;
float circumference[i];
float area[i];
circleno = i;```
Ehm, what is the value of i when you set up those arrays ?

--
Mats

4. well i = circleno and "circleno" is the number of circles the user imputs to enter radi for. should i move it down in the code under the first printf and scanf like this?

Code:
```#include <stdio.h>
#define PI 3.14159265
int main (void)
{
int circleno;
int j;

printf("Please enter the number of circles (max = 10):\n");
scanf("%i", &circleno);

float circumference[i];
float area[i];
circleno = i;```

5. ok i figured it out. however there is now a NEW problem...

heres what the code looks like, but its not calculating the circumference and area for each radi entered. only the last one...maybe a loop?
Code:
```#include <stdio.h>
#define PI 3.14159265
int main (void)
{
int circleno;
int j;
int i;
circleno = i;

printf("Please enter the number of circles (max = 10):\n");
scanf("%i", &circleno);

float circumference[i];
float area[i];

if ( circleno > 10 )
printf("Error -> %i circles is to many. Please try again:\n", circleno );
else
for ( j = 1; j <= circleno; ++j ) {
printf("Enter the radius for circle #%i:\n", j);
}

printf("circumferences = %f\n", circumference[i]);
printf("areas = %f\n", area[i]);

}```

6. You have the loop, but you don't have the area and circumference elements within it. You should easily see this as these elements are outside of your loop.

7. Actually, I don't see how that code has fixed anything - it is still as broken [but maybe you got lucky and i is a different value now when you have rearranged the code?]

Right, so you need a loop that BOTH reads the data and calculates whatever you are calculating (or two loops, one for reading the data, and one for calculating it).

Also, you are reading in radius[i], when you are using j to loop around. i is still not set to anything.

Further, you still make calculations even after you said "too many circles".

--
Mats