# Arrays problem

Page 1 of 1

## 2 Replies - 1815 Views - Last Post: 16 November 2012 - 11:41 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=300420&amp;s=0492b9e41a195e5a5119b491616344ce&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 rubydazey5

• New D.I.C Head

Reputation: 0
• Posts: 4
• Joined: 14-November 12

# Arrays problem

Posted 15 November 2012 - 11:14 PM

Ok I am taking C# in college and am stuck on this arry problem here is my code so far

```using System;
namespace Project6Chap7
{
class Arrays
{
static void Main( )
{
int[] aNum = new int[1000];
int[] i = new int[1000];
string inValue;

int aNumCount = 0;
int total = 0;
Console.Write("Enter a number 1 to 100: "
+ "(or -99 to exit)", aNumCount + 1);

while(inValue != "-99")
{
aNum[aNumCount] = Convert.ToInt32(inValue);
++aNumCount;
Console.WriteLine("Enter a number 1 to 100: "
+ "(or -99 to exit)", aNumCount + 1);
inValue = Console.ReadLine( );
}

foreach (int val in aNum)
{
total += val;
}
Console.WriteLine("Total: " + total);

Console.WriteLine("The first value entered was: " + i);

}
}
}
```

it runs fine so far but my question is how do I call the first number entered. I have tried several different ways but I either get -1 or ToInt32

This post has been edited by Martyr2: 15 November 2012 - 11:29 PM
Reason for edit:: Fixed code tags. [code]code in here[/code]. Thanks! :)

Is This A Good Question/Topic? 0

## Replies To: Arrays problem

### #2 Martyr2

• Programming Theoretician

Reputation: 4618
• Posts: 12,673
• Joined: 18-April 07

## Re: Arrays problem

Posted 15 November 2012 - 11:32 PM

Try this line...

```Console.WriteLine("The first value entered was: " + aNum[0].ToString());

```

Here we are saying "get the first value from the array of integers named aNum". You stored the first entry typed in aNum[0] when you went through the first time in your while loop. aNumCount was zero on that first time through.

This post has been edited by Martyr2: 15 November 2012 - 11:32 PM

### #3 heinbau

• New D.I.C Head

Reputation: 4
• Posts: 22
• Joined: 08-November 12

## Re: Arrays problem

Posted 16 November 2012 - 11:41 AM

What he said, the only thing that you need to remember (and it messed me up a few times!) is that arrays start their counting at '0' There was a situation where I spent more time than I care to admit trying to solve that problem, and I will never ever ever forget again