# Creating arrays and calculations

I need to create a program in C# that will accepts 10 scores with values of 1-10 and put them in an array, then create an other array representing what percentage of 100 the scores represent. I'm not really sure where to begin. Can anyone offer any suggestions?
~TIA
###### Who is Participating?

Software ArchitectCommented:
each time you input a new number you should accumulate a total, so at the end of input you will be able to evaluate each score as percentage:

static void Main(string[] args)
{
int[,] score = new int[10, 2];
string InValue;
int total = 0;   // <-------------- accumulator
int value;   // <------------ instant value

for(int i = 0; i <= 10; i++)
{
Console.WriteLine("Enter scores: ");
value = Convert.ToInt32(InValue);
score[i, 0] = value;
total += value;
}
}

well after this first for() loop, you will need a second for() loop to determine the percentage as:

percentage = value * 100 / total;
0

Software ArchitectCommented:
you can create a two dimensional array:

int score[][] = new int[10][2];

so, for score write to score[i][0] and for percentages write to score[i][1]
0

Author Commented:
That gives me a Error Bad array declarator error. Any other suggestions?
``````    class Program
{
static void Main(string[] args)
{
int score[][] = new int[10][2];
int InValue;

Console.WriteLine("Enter 10 scores: ");
}
``````
0

Software ArchitectCommented:
sorry, mixing C# with C++ (too much work!!), correct way in C# is:

int[,] score = new int[10,2];
0

Author Commented:
I think I have the array filling with the scores, but now how do I do the calculation representing what percentage of 100 the scores are in the second array?
``````    class Program
{

static void Main(string[] args)
{
int[,] score = new int[10, 2];
string InValue;

for(int i = 0; i <= 10; i++)
{
Console.WriteLine("Enter scores: ");
score[i, 0] = Convert.ToInt32(InValue);

}
}
}
}
``````
0

Commented:
Something like this?

``````for (int i = 0; i < scores.GetUpperBound(0); i++) {
scores[i][1] = Math.Round(scores[i][0] / maxScore, 2) * 100;
} //where maxScore is the maximum value of the score.
``````
0

Commented:
Sorry, the correct line should be

``````scores[i,1] = Convert.ToInt32(Math.Round(scores[i,0] / maxScore, 2) * 100);
``````
0

Author Commented:
Thanks for the help, but it still seem to be missing something. This is all fairly new to me, so any suggestions would be greatly appreciated.
``````        static void Main(string[] args)
{
int[,] score = new int[10, 2];
string InValue;
int total = 0;
int value;
int percentage;
int maxScore;

for(int i = 0; i <= 10; i++)
{
Console.WriteLine("Enter scores: ");
value = Convert.ToInt32(InValue);
score[i, 0] = value;
total += value;

for (int j = 0; j < score.GetUpperBound(0); j++)
{
score[j, 1] = Convert.ToInt32(Math.Round(score[j, 0] / maxScore, 2) * 100);
percentage = value * 100 / total;
Console.WriteLine(score[i, j]);
}
}
}
}
}
``````
0

Software ArchitectCommented:
appears to be you need a litte variation:

static void Main(string[] args)
{
int[,] score = new int[10, 2];
string InValue;
int total = 0;
int value;
int percentage;
int maxScore;

for(int i = 0; i <= 10; i++)
{
Console.WriteLine("Enter scores: ");
value = Convert.ToInt32(InValue);
score[i, 0] = value;
total += value;
}    // close loop here

for (int j = 0; j < score.GetUpperBound(0); j++)
{
score[j, 1] = Convert.ToInt32(Math.Round(score[j, 0] / maxScore, 2) * 100);
percentage = value * 100 / total;
Console.WriteLine(score[i, j]);
}
}
}
}
0

Author Commented:
static void Main(string[] args)
{
int[] score = new int[10];
string InValue;
int total = 0;
int value;
Double Ave;

for (int i = 0; i < 10; i++)
{
Console.WriteLine("Enter scores: ");
value = Convert.ToInt32(InValue);
//score[i, 0] = value;
score[i] = value;
// total += value;
}

Array.Sort(score);
for (int i = 1; i < 9; i++)
{
total += score[i];
}
Ave = total / 8;
Console.WriteLine("\nAverage = "+ Ave);