I'm writing a program which reads a couple of lines from a text file, each line contains a name and a score, for example: "Robert Plant: 50". The program then outputs which person had the highest score and the score of that person.
But I'm stuck on how to modify the line with the name and score, to only the name; another example: "Peter Griffin: 50" to "Peter Griffin".
I'm also not sure on how to determine which person has won, I know how to output the highest score, but how do I connect the name to the score?
My code is down below (don't mock me for it being badly written, I'm a beginner):
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
usingnamespace std;
void creatingName(vector<string> *rader){
// HOW DO I DO THIS? HERE IS WHERE THE NAME IS SUPPOSED TO BE SEPARATED FROM THE SCORE.
}
void creatingNumber(vector<int> *number, vector<int> *assembledNumber){
int n = number->size(), sum = 0;
for(int x=0;x<n;x++){
sum += (*number)[x]*pow(10,n-1);
}
assembledNumber->push_back(sum);
number->clear();
}
void determiningRows(vector<string> *rader){
fstream file;
file.open("exam.txt");
string line;
while(getline(file, line)){
if(line == "")
break;
rader->push_back(line);
}
}
int main(){
vector<string> rader;
fstream file;
vector<int> number, assembledNumber;
file.open("exam.txt");
determiningRows(&rader);
for(int x=0;x<rader.size();x++){
int n = rader[x].size();
for(int y=0;y<n;y++){
char c = rader[x][y];
if(isdigit(c)){
int a = c-48;
number.push_back(a);
}
}
creatingNumber(&number, &assembledNumber);
}
sort(assembledNumber.begin(), assembledNumber.end());
// NOT FINISHED HERE!
file.close();
}
PS. If you have any suggestions for shortening the code that I've already written, go ahead.