Trouble with array

I am trying to write a program that records an unspecified amount (at least 10) of integers in an array, and then print each int after they have all been recorded, however when I try to print them "ary[totalcounter]" says it is undefined.

Any advice? I'm new to this.
Thanks.


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
66
67
68
69
70
71
72
73
74
  #include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <windows.h>

int main()
{
	int counter, temp, done, c, d, temp2, temp3, total, totalcounter;
	
	counter = 0;


	for( done = 2; done != 1; done++)
	{
		
		
		int ary[1000];

		printf("\n \n Enter your data \n ->:");

		scanf("%i", &temp);

		ary[counter] = temp;

		counter = counter + 1;
		
		printf("%d", done);
		if (counter > 9)
		{
			for( temp3 = 2; temp3 != 1; temp3++)
			{
			printf("\nEnter 2 if you are finished entering data. \nEnter 1 if you have more data.\n ->:");
			scanf("%i", &temp2);

			if (temp2 == 2)
			{
			done = 0;
			temp3 = 0;
			}
			else{
			if (temp2 == 1)
			{
			temp3 = 0;}
			else
				printf("\nCould not understand imput\n");
			}
		}
		}


		
	}
	printf("You have %d elements in your vector \n", counter);
	
	
	
	//printing the elements of the array
	
	printf("The elements are: \n");
	totalcounter = counter;
	while (totalcounter != 0)
	{
		
	temp = ary[totalcounter];
	
	printf("%d", temp);

		totalcounter = totalcounter -1;
	}    
	return(0);
}
Looks like you leave the scope of the for loop where the array was initialized on line 25.
Thank you, so much, I didn't realize that that could be an issue.
Topic archived. No new replies allowed.