### Bubble sort more than 2 vectors? help!

TLDR;

 ``1234567891011121314151617`` `````` for (int j = 0; j days[i+1]){ days.push_back(i), months.push_back(temp1); years.push_back(temp2); appointments.push_back(temp3); } } }``````

This code does not work. I posted more on the bottom.

Can someone help me with what I am doing wrong?
it says " (int k = 0; k<years.size()-1;++k)" reqs an expression
but I want it all in the same loop, so it increments and moves them all at the same time. How do I do that?

Really new to C++

Trying to figure out how to bubble sort more than 2 things.

Here is my code. I did 1 string, and 1 date. I was able to
 ``1234567891011121314151617181920212223242526272829303132333435363738394041`` `````` int main () { int a = 0; vector appointments; string appointment; vector dates; int date; string yes; string temp; while( a < 99) // limiting you to 99 appointments you HARD WORKING MAN YOU! { cout << " enter a name for an appointment" <<"\n"; std::cin >> appointment; appointments.push_back (appointment); cout << "enter Year month day 'example 2013 04 25' No spaces' like '20130425' 'type a zero first before month #, and same for days' " <<"\n"; std::cin >> date; dates.push_back (date); cout << "Would you like to stop adding appointments? type 'Yes' if you do or 'No' to keep going" <<"\n"; cin>>yes; if(yes=="Yes"){ break; } else{ continue; } a++; } for (int j = 0; j dates[i+1]){ dates.push_back(i); appointments.push_back(temp); } } }``````

 ``123456789`` ``````for (int j = 0; j dates[i+1]){ dates.push_back(i); appointments.push_back(temp); } } }``````

This works

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364`` `````` int main () { int a = 0; vector appointments; string appointment; vector years; vector months; vector days; int year; int month; int day; string yes; string temp1; string temp2; string temp3; while( a < 99) // limiting you to 99 appointments you HARD WORKING MAN YOU! { cout << " enter a name for an appointment -- 'NO SPACES' --" <<"\n"; std::cin >> appointment; appointments.push_back (appointment); cout << "enter Year example: '2013' " <<"\n"; std::cin >> year; years.push_back (year); cout << "enter month example: '5' " <<"\n"; std::cin >> month; months.push_back (month); cout << "enter day example: '15' " <<"\n"; std::cin >> day; days.push_back (day); cout << "Would you like to stop adding appointments? type 'Yes' if you do or 'No' to keep going" <<"\n"; cin>>yes; if(yes=="Yes"){ break; } else{ continue; } a++; } for (int j = 0; j days[i+1]){ days.push_back(i), months.push_back(temp1); years.push_back(temp2); appointments.push_back(temp3); } } }``````

This does not, I split dates into 3 other vectors, years months and days.

TLDR;

 ``1234567891011121314151617`` `````` for (int j = 0; j days[i+1]){ days.push_back(i), months.push_back(temp1); years.push_back(temp2); appointments.push_back(temp3); } } }``````

This code
Should I do

 ``123456789`` `````` for (int j = 0; j days[i+1]){ days.push_back(i); months.push_back(temp1 ); } } }``````

 ``123456789`` `````` for (int k= 0; k days[i+1]){ days.push_back(i); years.push_back(temp2 ); } } }``````

 ``123456789`` `````` for (int l= 0; l days[i+1]){ days.push_back(i); appointments.push_back(temp3 ); } } }``````

But would that pushback the days vector 3x every time each of of the oher one gets pushed? cause I don't want it to do that.
I haven't really looked at your code, but you should just do something like this for your loop:

 ``1234567891011121314151617`` ``````for (int j = 0; j days[i+1]) { days.push_back(i), months.push_back(temp1); years.push_back(temp2); appointments.push_back(temp3); } } }``````
@fg109 ah thank you!!!!

its ok if you haven't read it lol, just by reading your first line I i already knew it would fix it haha .

Really thanks again, and I suck so much at this.
O.o

79:26: error: no matching function for call to âVector<int>::push_back(String&)â

This line
-(12)-- > months.push_back(temp1);

EDIT:
lol forgot its a string and not int. Let me see if that fixes it

Why yes... yes it does fix it. Thanks again!
Last edited on
Looks like there are a number of things off actually.

`for (int j = 0; j<months.size()-1;++j)`

 ``12`` ``````(int k = 0; k

These are lost souls. I'm guessing you want it to belong with the for loop, but a for loop doesn't work that way. You can just add a for in front of each of those statements (admittedly I have no idea what you're doing with them).

temp1, temp2 and temp3 are type string. months and years are type int. You can't convert an int to a string this way.

 ``123`` ``````temp1 = months[j]; temp2 = years[k]; temp3 = appointments[l];``````

Again, you can't convert strings to int in this way so the compiler won't let you.

 ``123`` ``````days.push_back(i), months.push_back(temp1); years.push_back(temp2);``````

Try sort() http://www.cplusplus.com/reference/algorithm/sort/

Edit: Late, so late.
Last edited on
@Olysold

Hey Thanks a lot for respond :D.

Using fg109 post worked. Again Thank you all for help!
Topic archived. No new replies allowed.