I recommend you look at the reference files for vectors. In short, that is not how you read values in a vector. You need an iterator, not just a standard number, to read specific values.
#include <iostream>
#include <vector>
usingnamespace std;
int main()
{
int amountMade;
int numOfEmployees;
int percentOfWork;
string namesOfEmployees;
vector<string> vect_Employees;
vector<string>::iterator string_iter;
vector<int> vect_percentage;
vector<int>::iterator int_iter;
cout << "Royalty Calculator" << endl;
cout << "How much money was made this month from project?" << endl;
cout << "$";
cin >> amountMade;
cout << '\n';
cin.ignore(500, '\n');
cout << "What are the employees names? Enter 'done' when finished" << endl;
while(namesOfEmployees != "done")
{
getline(cin, namesOfEmployees);
for(int i = 0; i < 1; i++)
{
vect_Employees.push_back(namesOfEmployees);
}
}
vect_Employees.pop_back();
cout << '\n';
cout << "What percent of work did each individual do?" << endl;
int num = 1;
int vect_Length = vect_Employees.size();
int vect_Lenght_int = vect_percentage.size();
for(string_iter = vect_Employees.begin(); string_iter != vect_Employees.end(); ++string_iter)
{
cout << num << " " << *string_iter;
cout << " %";
cin >> percentOfWork;
vect_percentage.push_back(percentOfWork);
cout << endl;
num++;
}
cout << '\n';
cin.ignore(500, '\n');
cout << "Payment to each worker" << endl;
for(string_iter = vect_Employees.begin(), int_iter = vect_percentage.begin();
string_iter != vect_Employees.end(), int_iter != vect_percentage.end();
++string_iter, ++int_iter)
{
cout << *string_iter << " %";
cout << *int_iter % amountMade << endl;
}
return 0;
}
It works now which is great, thanks for correcting me. Now im having a math problem, I have a math iq of 7 so if you can help me that would be much appreciated. In the very last for loop, this part:
im trying to output the percentage of money each person will get, so i enter an amount in the beginning and all of the team members and then it outputs everyones pay but i cant seem to get it to do that.
What is it you're trying to achieve with the condition on the second line of that snippet? Do you really want to use the comma operator there? I suspect you've misunderstood what the comma operator does, because it's hard to see how it makes sense there.
I dont know what i mean by that, i guess i really dont know what it does. I dont know that either, someone told me the way i was reading values in a vector was wrong and so they gave me a link and i followed it exactly.
Ok i read up on it and it is a seperator in some contexts but an evaluator in most contexts. i see now. well that for loop is supposed to output the contents of the vector so i guess i could do a nested for loop but isnt there a way to do an advanced for loop with that code? thats what i was trying to do but i guess that wont work, so i guess this would be the more sensible solution?
If you do a nested loop, then what well happen is that the inner loop will loop over all the members of vect_percentage for every member of vect_Employees. So if there were 5 elements in vect_Employees and 7 elements in vect_percentage then the inner loop would iterate 7 times for vect_Employees[0], then another 7 times for vect_Employees[1], etc - for a total of 35 times.
No i want it to show the names of the employees stored in vect_Employees, then calculate the percentages i entered for each person to see what they would get out of the amount of money i entered in the beginning, so lets say i enter $900, then i enter the employees names, then the percentage of work the employees did, then the program calculates what percent they would get and output it.
Well, the devil is in the details. From the way you've described it, it sounds like the output would look like:
Adam
Barbara
Chris
Daisy
100
235
163.6
43.99
Whereas from looking at your code, it looks like what you're trying to get is:
Adam 100
Barbara 235
Chris 163.6
Daisy 43.99
Since there is a direct one-to-one relationship between employee and percentage, why are you confusing things by trying to manage two vectors at once? Why not have a struct that contains the name and the earnings of each employee, and then have a single vector of structures? That way, you only have to manage a single iterator.
well this is a program i am using in real life for my indie game company to compute the royalty earnings of my employees so i cant have fixed values or names.
I'm saying that instead of having one vector that contains names, and another that contains earnings, you should define a struct type that bundles together that information for an employee, and then have a single vector of those structs.
You don't know how to write a struct? To be honest, you'd be better off reading a proper C++ book to learn this stuff, rather than asking piecemeal questions on a forum.
The struct is really simple:
1 2 3 4 5
struct Employee // This is the name of the type
{
string name;
float percentage;
}
Make a single vector of Employee structs, rather than the two vectors you have now, so you only have to worry about iterating over a single vector. Store the name and percentage of each employee in the struct for that employee.
If you don't know how to use structs, then I'll reiterate my previous comment:
you'd be better off reading a proper C++ book to learn this stuff, rather than asking piecemeal questions on a forum.
Edit: you say you have a games company - you mean a computer games company? As in, you have actual software developers already working for you?