For my assignment all we are required to do is stream in the .txt and just use whatever method we want, to output the correct data. I chose this way because I'm least familiar with this style. Any help would be greatly appreciated as I am new to coding.
So this is what is commonly called a comma separated value or CSV file. This is pretty self explanatory but just in case, it means that each field is separated by a comma. The inclusion of the "Algorithm" header suggests that your teacher expects you to know about things like templates, if this is the case then you'll want to use "Count()" to determine the number of commas in each line and then dynamically create a string array based on that, then I would normally suggest using "strtof()" to convert the strings to floating points and determine which field is the label simultaneously but for that you would need to add the "cstdlib" header. Then it's just a matter of adding up the numbers and formatting the output.
This is now what I have, I had used <sstream> which i mildly grasp the concept of. I have parsed out the numbers that I need from the words, now I just need to figure how to use one of the conversions from a string to a float, such as atof. I commented certain situations that I found.
int size = 9;
string delimiter = ",";
size_t pos = 0;
string * rainFall;
rainFall = new string[size];
for(int i = 0; i < size; i++)
while ((pos = rainFall[i].find(delimiter)) != string::npos)
token = rainFall[i].substr(0, pos);
//prints out just rainfall before city name(w/o line 33)
//prints out everything correctly(w/ line 33)
cout << token << endl;
rainFall[i].erase(0, pos + delimiter.length());
cout << rainFall[i] << endl;
//this alone prints out just city names
//cout << token << endl;
//this alone prints out city then the rainfall after last comma
//cout << token << rainFall[i] << endl;
//outputs the end of first line after last dilemeter
//parsed array isn't saved back into original array
cout << rainFall << endl;
/*for(int i = 0; i < size; i++)
cout << rainFall[i] << endl;
You look like you have a handle on it. I still think you should work std::count into there, that would make your dynamic arrays look more impressive. The 'token' string should probably be an array of some sort otherwise you're looping through and overwriting your previous values and the sample output suggests that you want to add those values together.
Ok, ignore all other questions, I was doing it the difficult way.. Now I have the correct look on the output besides the adding isn't working right. The first city adds correct then the others do as I commented in below. An example input file is posted above
Thank you, now I just need to figure out the double output of the last city. And the code thing is easy, this site is I believe java based, so its [c0de] to start then [/c0de] to end, and of course replace the 0's with o's.