1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Calculating yes and no for attendance from input file. C++

Discussion in 'C++' started by Zax, Dec 5, 2016.

Tags:
  1. Zax

    Zax New Member

    Joined:
    Dec 4, 2016
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    Hey guys, I want to calculate the amount of attendance of yes and no of each student from csv.file. Can anyone help me on how to extract the each string to calculate with for loop?

    Here is my code:
    Code:
    void task1(){
    string line,token;
    ifstream fin("Data.csv");
    string attendance[10];
    int i=0;
    
    if (fin.is_open()){
    while (getline(fin, line)){
    stringstream ss(line);
    
    for (i = 0; i < 10; i++){
    getline(ss, token, ',');
    attendance = (token.c_str());
    }
    cout << "Attendance: ";
    for (i = 0; i < 10; i++){
    cout << attendance << " ";
    }
    }
    fin.close();
    cout<<endl;
    }else{cout << "Couldn't open the file \n" << endl;
    fin.close();}
    }
    
    File: [Data.csv]
    yes, yes, yes, no, yes, yes, no, no, no, yes (student 1)
    no, yes, yes, no, yes, yes, yes, yes, no, yes (student 2)
    yes, yes, yes, no, yes, yes, no, no, no, yes (student 3)
    yes, 1, yes, no, yes, yes, no, yes, no, yes (student 4)
     

Share This Page