Click here to Skip to main content
15,887,214 members
Home / Discussions / C#
   

C#

 
SuggestionRe: Console Check (Part II) Pin
Richard MacCutchan11-Apr-13 6:00
mveRichard MacCutchan11-Apr-13 6:00 
GeneralRe: Console Check (Part II) Pin
Bassam Abdul-Baki11-Apr-13 6:34
professionalBassam Abdul-Baki11-Apr-13 6:34 
SuggestionRe: Console Check (Part II) Pin
Eddy Vluggen11-Apr-13 8:05
professionalEddy Vluggen11-Apr-13 8:05 
GeneralRe: Console Check (Part II) Pin
jschell11-Apr-13 11:10
jschell11-Apr-13 11:10 
GeneralRe: Console Check (Part II) Pin
Bassam Abdul-Baki11-Apr-13 11:30
professionalBassam Abdul-Baki11-Apr-13 11:30 
QuestionC# cystal report using mysql Pin
alam12310-Apr-13 20:40
alam12310-Apr-13 20:40 
AnswerRe: C# cystal report using mysql Pin
Abhinav S10-Apr-13 20:51
Abhinav S10-Apr-13 20:51 
Questioncalculating grades with files and arrays Pin
Magda634710-Apr-13 18:46
Magda634710-Apr-13 18:46 
I need to calculate total grades for students with files and arrays. user first enters course they are calculating grades from. all data files use this course file as part of their name. Outer loop to read the records from the master name file. Inner loop or loop insidefunction to read the records for each student.When processing the records from a student file each one should be done separately and not assumed they are grouped in any particular order.
Program reads a record, decides what category it is in updates the running total for that category. Once the entire file has been read, you can compute the average for each category based on the number of items that should be in that category, which may be more than the number of records in the file for items turned in.

I am horrible and I mean horrible at this and I have literally put in about 35 hours into trying to make this work and this is my 8th program I have redone and really need any guidance on what I should do or if I should restart again or what I am doing wrong.

I am receiving errors on line 29 "unexpected symbol 'while' in class,struct, or interface member declaration and

line 29 and 32 "unexpected symbol ')' in class, struct or interface member declaration"

line 36 "unexpected symbol 'string',expecting 'class','delegate', 'enum',..."


C#
using System;
using System.IO;
using System.Collections.Generic;
using IntroCS;


namespace GradeProgram {

    class Gradebook {

        static void Main()
        {


            string fileName = UIF.PromptLine ("Please enter the comp course with no spaces: ");
            string categoryFileName = "categories_" + fileName + ".txt";
            var reader = new StreamReader (categoryFileName);

            while (!reader.EndOfStream) {
                string line = reader.ReadLine ();
                Console.WriteLine (line);

            }
        }

            string studentFileName = "student_" + fileName + ".txt";

            var reader2 = new StreamReader (studentFileName);
            while (!reader2.EndOfStream) {
                string student = reader2.ReadLine ();
                Console.WriteLine (student);
        }

        }

        static string[] GetStringArray(string input)
        {
            string[] parts = input.Split(',');
            return parts;
        }

        static int[] GetIntArray(string input)
        {
            string[] parts = input.Split(',');
            int[] intparts = new int[parts.Length];
            for (int i = 0; i < parts.Length; i++)
                intparts[i] = int.Parse(parts[i]);
            return intparts;
        }

        static int codeIndex(string code, string[] categories)
        {
            for (int i = 0; i < categories.Length; i++)
            {
                if (categories[i].StartsWith(code))
                {
                    return i;
                }
            }
            return -1;
        }

        static string[] GetCatNames(string file)
        {


            var reader = new StreamReader(file);

            string categories = reader.ReadLine();
            string[] catnames = GetStringArray(categories);
            for (int i = 0; i < catnames.Length; i++)
                Console.WriteLine("Category at position {0} = {1}", i, catnames[i]);
            return catnames;
        }

        static int[] GetWeights(string file)
        {

            int targetLine = 2;
            int counter = 1;
            int[] weightvalues = new int[0];
            var reader = new StreamReader(file);
            while (!reader.EndOfStream)
            {

                string weights = reader.ReadLine();
                if (counter == targetLine)
                {
                    weightvalues = GetIntArray(weights);
                }
                counter++;
            }
            for (int i = 0; i < weightvalues.Length; i++)
            {
                Console.WriteLine("Category at position {0} = {1}", i, weightvalues[i]);
            }
            return weightvalues;

        }

        static int[] GetNumOfItems(string file)
        {
            int targetLine = 3;
            int counter = 1;
            int[] itemsvalues = new int[0];
            var reader = new StreamReader(file);
            while (!reader.EndOfStream)
            {
                string items = reader.ReadLine();
                if (counter == targetLine)
                {
                    itemsvalues = GetIntArray(items);
                }
                counter++;
            }
            for (int i = 0; i < itemsvalues.Length; i++)
            {
                Console.WriteLine("Category at position {0} = {1}", i, itemsvalues[i]);
            }
            return itemsvalues;
        }

        static string[] GetStudent(string file)
        {

            var reader = new StreamReader(file);
            //string student = reader.ReadLine();
            //string[] studentnames = GetStringArray(student);
            //int targetLine = 3;
            //int counter = 1;
            //string[] itemsvalues = new string[0];

            while (!reader.EndOfStream)
            {
                string items = reader.ReadLine();
                //if (counter == targetLine)
                //{
                string[] itemsvalues = GetStringArray(items);
                for (int i = 0; i < itemsvalues.Length; i++)
                    Console.WriteLine("Category at position {0} = {1}", i, itemsvalues[i]);
                //}
                //counter++;
            }

            //return studentnames;
            return null;


        }

        }}



AnswerRe: calculating grades with files and arrays Pin
PIEBALDconsult10-Apr-13 19:05
mvePIEBALDconsult10-Apr-13 19:05 
AnswerRe: calculating grades with files and arrays Pin
Abhinav S10-Apr-13 19:07
Abhinav S10-Apr-13 19:07 
GeneralRe: calculating grades with files and arrays Pin
Magda634710-Apr-13 19:38
Magda634710-Apr-13 19:38 
AnswerRe: calculating grades with files and arrays Pin
Abhinav S10-Apr-13 19:49
Abhinav S10-Apr-13 19:49 
AnswerRe: calculating grades with files and arrays Pin
V.11-Apr-13 19:57
professionalV.11-Apr-13 19:57 
Questionsmartcard application Pin
prasannakumarV10-Apr-13 18:21
prasannakumarV10-Apr-13 18:21 
AnswerRe: smartcard application Pin
Abhinav S10-Apr-13 19:44
Abhinav S10-Apr-13 19:44 
Questionfirst row blank when export from gridview to excel with master pages included project Pin
Dhyanga10-Apr-13 10:56
Dhyanga10-Apr-13 10:56 
AnswerRe: first row blank when export from gridview to excel with master pages included project Pin
Dhyanga11-Apr-13 4:03
Dhyanga11-Apr-13 4:03 
Questionmaking a desktop lights app Pin
Johnny English10-Apr-13 4:44
Johnny English10-Apr-13 4:44 
AnswerRe: making a desktop lights app Pin
Eddy Vluggen10-Apr-13 5:06
professionalEddy Vluggen10-Apr-13 5:06 
GeneralRe: making a desktop lights app Pin
Johnny English10-Apr-13 5:18
Johnny English10-Apr-13 5:18 
AnswerRe: making a desktop lights app Pin
Eddy Vluggen10-Apr-13 6:52
professionalEddy Vluggen10-Apr-13 6:52 
GeneralRe: making a desktop lights app Pin
Johnny English10-Apr-13 10:30
Johnny English10-Apr-13 10:30 
GeneralRe: making a desktop lights app Pin
Eddy Vluggen10-Apr-13 11:08
professionalEddy Vluggen10-Apr-13 11:08 
GeneralRe: making a desktop lights app Pin
Johnny English10-Apr-13 20:37
Johnny English10-Apr-13 20:37 
AnswerRe: making a desktop lights app Pin
Clifford Nelson10-Apr-13 11:04
Clifford Nelson10-Apr-13 11:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.