English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm having some issues with adding in C#, I keep getting errors saying "sum does not exist in the class or namespace". I can't seem to get the values to add and get an average.

2006-11-12 14:52:45 · 2 answers · asked by Christina 2 in Computers & Internet Programming & Design

Here is the code I am writing:
public class testScores
{
public static void Main()
{
int value1 = 95,
value2 = 98,
value3 = 99,
value4 = 100,
value5 = 89;
Console.WriteLine ("The sum of {0},{1},{2},{3},{4} is {5}",value1,value2,value3,value4,value5,sum);

2006-11-12 15:04:52 · update #1

2 answers

Did you mean the sum function? If you refer to the sum method or function, it is not defined anywhere in the c# library. You have to make it yourself.

The easiest way to do so is like this: make a simple function as in c or c++ with a return parameter integer, taking an array of integer as an input parameter. The algorithm is quite easy, using a loop, add the variables of the previously assigned array value to the next in the array.
while....//while body
//.....
sum = sum + array[i];
i = i+1;
//continue looping..
Easy?

2006-11-12 15:05:17 · answer #1 · answered by m_Fariz 3 · 0 0

what exactly are you typing, did u #include

2006-11-12 15:01:03 · answer #2 · answered by Hydronle 2 · 0 0

fedest.com, questions and answers