need help finishing the c++ program

Pages: 12
thank you for that and one last thing im trying to add up the salaries of the presidents i thought because their salaries come in as strings i could convert the strings to doubles and then add that salary to the total salary and it would do it for each salary it found but i get an error heres my code
1
2
3
4
5
6
7
8
9
while (getline (in, line)){ // using getline to read in a single line at a time
		string id, firstname, lastname, salary;
		istringstream iss (line);
		iss >> id >> firstname >> lastname >> salary >> total;
		Presidents person (firstname, lastname, salary, id);
		sort.push_back (person);
		double money = std::stod (salary);
		total = money + total;
}


the out put is this number 7.29112e-304
1
2
3
4
5
6
7
8
9
while (getline (in, line)){ // using getline to read in a single line at a time
		string id, firstname, lastname;
                double salary;
		istringstream iss (line);
		iss >> id >> firstname >> lastname >> salary >> total;
		Presidents person (firstname, lastname, std::to_string(salary), id);
		sort.push_back (person);
		total = salary + total;
}
Last edited on
i get compiler errors from that

NPP_EXEC: "Compile C++ File"
NPP_SAVE: C:\Users\lords_000\Downloads\pocketcpp\lab11.cc
g++ -o "C:\Users\lords_000\Downloads\pocketcpp\lab11" "C:\Users\lords_000\Downloads\pocketcpp\lab11.cc" -static -std=c++14
Process started >>>
C:\Users\lords_000\Downloads\pocketcpp\lab11.cc: In function 'void get_line(std::ifstream&, std::ofstream&)':
C:\Users\lords_000\Downloads\pocketcpp\lab11.cc:86:10: error: conflicting declaration 'double salary'
double salary;
^~~~~~
C:\Users\lords_000\Downloads\pocketcpp\lab11.cc:85:35: note: previous declaration as 'std::__cxx11::string salary'
string id, firstname, lastname, salary;
^~~~~~
C:\Users\lords_000\Downloads\pocketcpp\lab11.cc:89:65: error: no matching function for call to 'to_string(std::__cxx11::string&)'
Presidents person (firstname, lastname, std::to_string (salary), id);

i get more than this but most of it is useless info
Last edited on
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/general/213121/
Topic archived. No new replies allowed.
Pages: 12