I've figured out how to do most of what I need. I realize that the variables used in the for loops will not be reachable outside of the loop, but I need to display the sum of the integers the user puts in. So,
step 1: Asks user for input of number of integers.
Step 2: Runs through getting each integer.
Step 3: Then displays all input.
And step 4: should have the sum of step 3...and that's
where my issue is.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Dynamic_Entry
{
class Program
{
static void Main()
{
Console.Write("How many integers are in your list? ");
int k = Convert.ToInt32(Console.ReadLine());
int[] a = new int[k];
int sum = 0;
for (int i = 0; i < a.Length; i++)
{
Console.Write("Please enter an integer: ");
a[i] = Convert.ToInt32(Console.ReadLine());
}
for (int n = 0; n < a.Length; n++)
{
Console.WriteLine("{0, 5}", a[n]);
}
Console.WriteLine("-----");
sum += [] a;
Console.Write("{0, 5}", sum);
Console.ReadLine();
}
}
}
Any help on how to get the sum from outside the loop? If I put the hyphen line inside the last loop, it'll keep putting lines after every number...I only need the line at the end, with the sum under it. Thanks!
int sum = 0;up top, thensum += a[i];as you read them in.