-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
80 lines (61 loc) · 1.28 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* main.cpp
*
* Created on: Jul 6, 2016
* Author: RLi
*/
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <stack>
#include <iterator>
#define DATAPOINTS 14
using namespace std;
int main(){
string fileName;
ifstream dataFile;
ofstream file;
file.open("Data Summary.csv");
do{
cout << "Enter a csv file: ";
cin >> fileName;
dataFile.open(fileName.c_str(), ios::in);
} while(!dataFile.good());
string line;
if (!getline(dataFile, line)){
cerr << "The csv file is empty." << endl;
return EXIT_FAILURE;
}
int gameNum = 0;
int solutionNum = 0;
while (getline(dataFile, line)){
istringstream lineStream(line);
string data;
getline(lineStream, data, ',');
if (stoi(data) != gameNum && gameNum != 0){
file << solutionNum << endl;
gameNum = stoi(data);
file << gameNum << ",";
for (int i = 1; i < 7; i++){
getline(lineStream, data, ',');
file << data << ",";
}
solutionNum = 1;
} else if (gameNum == 0){
gameNum = stoi(data);
file << gameNum << ",";
for (int i = 1; i < 7; i++){
getline(lineStream, data, ',');
file << data << ",";
}
solutionNum++;
}else{
solutionNum++;
}
}
file << solutionNum << endl;
}