I need to use a loop to calculate average rather than the Array.Average() method

I need to use a loop to calculate average rather than the Array.Average() method and I'm very new with c++ so I don't have a lot of understanding for it (my prof is shit at teaching). The instructions are in the code as well and a bit of help with the output would be much appreciated too.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MidTermMarkCalculation
{
class Program
{
static void Main(string[] args)
{

/*
* DECLARATIONS
*/

const int NUMBER_OF_ICES_INCLUDED = 8; // for the number of all ICEs that count at present
const double OVERALL_ICE_VALUE = 0.20; // the percentage that ICEs are worth, overall

const int NUMBER_OF_CRCS_INCLUDED = 4; // for the number of all CRCs that count at present
const double OVERALL_CRC_VALUE = 0.40; // the percentage that CRCs are worth, overall

const int NUMBER_OF_LABS_INCLUDED = 2; // for the number of all Labs that count at present
const double OVERALL_LAB_VALUE = 0.40; // the percentage that Labs are worth, overall

double[] iceScores = new double[NUMBER_OF_ICES_INCLUDED];
double[] crcScores = new double[NUMBER_OF_CRCS_INCLUDED];
double[] labScores = new double[NUMBER_OF_LABS_INCLUDED];

double iceAverage = 0; // average ICE grade
double crcAverage = 0; // average CRC grade
double labAverage = 0; // average Lab grade

double overallAverage = 0; // average overall grade


/*
* INPUT
*/


{
Console.Write("Please enter your grade on ICE " + iceCounter + ": ");

if (Double.TryParse(Console.ReadLine(), out iceScores[iceCounter - 1]) == false)
{
Console.WriteLine("\nGrades must be entered as whole numbers.");
iceCounter--;
}
else if ((iceScores[iceCounter-1] < 0) || (iceScores[iceCounter-1] > 100))
{
Console.WriteLine("\nGrades must be between 0 and 100.");
iceCounter--;
}

}


for (int crcCounter = 1; crcCounter < NUMBER_OF_CRCS_INCLUDED + 1; crcCounter++)
{

Console.Write("Please enter your grade on CRC " + crcCounter + ": ");

if (Double.TryParse(Console.ReadLine(), out crcScores[crcCounter - 1]) == false)
{
Console.WriteLine("\nGrades must be entered as whole numbers.");
crcCounter--;
}
else if ((crcScores[crcCounter - 1] < 0) || (crcScores[crcCounter - 1] > 100))
{
Console.WriteLine("\nGrades must be between 0 and 100.");
crcCounter--;
}

}
.
for (int labCounter = 1; labCounter < NUMBER_OF_LABS_INCLUDED + 1; labCounter++)
{
Console.Write("Please enter your grade on LAB " + labCounter + ": ");

if (Double.TryParse(Console.ReadLine(), out labScores[labCounter - 1]) == false)
{
Console.WriteLine("\nGrades must be entered as whole numbers.");
labCounter--;
}
else if ((crcScores[labCounter - 1] < 0) || (labScores[labCounter - 1] > 100))
{
Console.WriteLine("\nGrades must be between 0 and 100.");
labCounter--;
}

}



/*
* PROCESSING
*/

// Determine the average of the ICE array, store this in the relevant variable

// *** AVERAGE METHOD 1 ***

iceAverage = iceScores.Average(); // this is the easy way to get an average from a
// numeric array; it is expressly forbidden on
// Lab 4, based on the requirements

// Determine the average of the CRC array, store this in the relevant variable

// *** AVERAGE METHOD 2 ***

// Here's another way to determine an average, which should seem
// familiar if you've watched the arrays videos
for (int crcCounter = 1 ; crcCounter < crcScores.Length + 1; crcCounter++)
{
crcAverage += (crcScores[crcCounter - 1] / NUMBER_OF_CRCS_INCLUDED);
// this is adding the scores on each CRC and dividing by the total number of CRCs
}


// *** YOU CAN COMPLETE THE PROCESSING FOR Labs ***
// Do this using a loop rather than the Array.Average() method.

// Determine the average of the Lab array, store this in the relevant variable


// Determine the total grade overall:
// Total grade overall: add the average of the ICE array multiplied by the value of the ICE array (0.20)
overallAverage += iceAverage * OVERALL_ICE_VALUE;

// Total grade overall: add the average of the CRC array multiplied by the value of the CRC array (0.40)
overallAverage += crcAverage * OVERALL_CRC_VALUE;

// Total grade overall: add the average of the Lab array multiplied by the value of the Lab array (0.40)
overallAverage += labAverage * OVERALL_LAB_VALUE;


/*
* OUTPUT
*/

// *** YOU CAN COMPLETE THE OUTPUT ***
// This should be easy; it's barely even array-related.

// Output the average of the ICE array (already determined above), with an appropriate identifier
// Output the average of the CRC array (already determined above), with an appropriate identifier
// Output the average of the Lab array (already determined above), with an appropriate identifier

// Output the total grade overall (already determined above), with an appropriate identifier.



// Prompt the user to press a key to exit
Console.Write("\nPress any key to exit... ");
Console.ReadKey();

}
}
}
Last edited on
Zenith0915 wrote:
I'm very new with c++ so I don't have a lot of understanding for it (my prof is shit at teaching).


Quite. But I infer from the post more about the student than the lecturer.

C++ ? I think you might have gone to the wrong class.
Last edited on
That code is C#, not C++.
The code doesn't even compile.
The name 'iceCounter' does not exist in the current context Program.cs(49)	
Topic archived. No new replies allowed.