/*
Lauren Dukes
CPSC 1110 Example

Uses a partially filled array to add up numbers.
Shows the consequences of reading past how far the array is full.

*/

#include <stdio.h>

int main(void){
	//Declare an array to hold up to 10 numbers
	int numbers[10];

	//declare variable to hold user input
	int in;

	//prompt user and get input
	printf("Enter a number, or -1 to quit.");
	scanf("%d",&in);

	//while there are fewer than 10 numbers and the user hasn't typed in -1
	int i = 0;
	for (i = 0; i < 10 && in != -1; i++){
		//put the number into the current array position
		numbers[i] = in;

		//ask user for the next number
		printf("Enter another number, or -1 to quit.");
		scanf("%d",&in);
	}

	//declare a variable to hold the sum
	int sum = 0;

	printf("%d\n",numbers[9]);

	//sum up all ten numbers in the array
	for (i = 0; i < 10; i++){
		sum = sum + numbers[i];
	}

	//print out the sum
	printf("Sum is %d\n",sum);

	return 0;
}

