Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C# problem - Reading and adding from file

  • 26-04-2006 3:01pm
    #1
    Registered Users, Registered Users 2 Posts: 10,209 ✭✭✭✭


    I'm doing a little practise before my exams in 2 weeks.

    Basicly, im writing a program that reads info from a file and displays it on screen, nice and simple.

    Now, lets say I have the following situation
    Name Sales Comission
    John 50 5
    Mary 100 10

    Now, ive gotten the info from the file using field[0], field[1] etc....

    BUT, how would I go about Adding the total sales together? Any help much appreciated! (Or a link to info on the web!)


Comments

  • Registered Users, Registered Users 2 Posts: 2,082 ✭✭✭Tobias Greeshman


    Why not as you read in a record you read each into an array of strings called field like you suggested. Then add name's to a string array, sales to an int array and commission to an int array.

    Something like this
    string [] field = new string [ 3 ] ;
    ArrayList names = new ArrayList ( ) ;
    ArrayList sales = new ArrayList ( ) ;
    ArrayList commision = new ArrayList ( ) ;
    
    while ( records to read )
    {
      //... Read in record 
      names.Add ( field [ 0 ] ) ;
      sales.Add ( field [ 1 ] ) ;
      commision.Add ( field [ 2 ] ) ;
    }
    
    int total_sales = 0 ;
    for ( int i = 0 ; i < sales.Count ; i++ )
       total_sales += (int)sales [i] ;
    


Advertisement