Can't Sort A Phonebook Program

Okay. So I've been given the task to make a phone book that saves at max 10 contacts along with their number. The list must be sorted when asked to display the saved results.
I've managed to make the list but the thing I can't figure out is the sorting. I've tried sorting it but at first it only sorted the first two entries and after I made some changes the program started to crash.
Here's my C++ code without the sorting codes I've tried. Please excuse me if it's poorly written I'm relatively new to programming and thank you in advance.
P.S: I would appreciate tips to help me get better at this.

#include "stdafx.h"
#include "iostream"
#include "string"
using namespace std;
int main()
{
int size = 0;int bazinga = 1;int choice;int mcounter = 2;string buffalo;
int dchecker = 0;string temp, temp2;
int checker = -1;
string mcn[10];
string csn[10];
cout << "Press 1 To Enter New Contact" << endl << "Press 2 To View Contacts" << endl << "Press 3 To Exit" << endl;
while (bazinga == 1)
{
cin >> choice;cout << endl;
if (choice <= 0 || choice > 3)
{
cout << "Invalid Input Please Re-Enter" << endl;
continue;
}
if (choice == 1)
{
size++;
cout << "Enter Contact's Name" << endl;
cin >> mcn[size - 1];
cout << "Enter Contacts Number" << endl;
cin >> csn[size - 1];cout << endl;

cout << "Press 1 To Enter New Contact" << endl << "Press 2 To View Contacts" << endl << "Press 3 To Exit" << endl << endl;
continue;
}
if (choice == 2)
{
if (size == 0)
{
cout << "Your Contact List Is Empty. Try Making Some Friends You Lame Ol' Loser" << endl << endl;
}
else
{
for (int dnnn = 0;dnnn < size;dnnn++)
{
cout << "Contact Number " << dnnn + 1 << " :" << endl;
cout << mcn[dnnn] << endl << csn[dnnn] << endl;
}
cout << endl;
}
cout << "Press 1 To Enter New Contact" << endl << "Press 2 To View Contacts" << endl << "Press 3 To Exit" << endl << endl;
continue;
}
if (choice == 3)
{
cout << "Goodbye" << endl;
break;
}
}
return 0;
}
Are there any restrictions of what you can use? If not I would suggest to create a struct to hold the name and the phone number and store them in a vector. You can easily sort the vector with the std algorithm sort.

1
2
3
4
5
6
7
8
struct Contact
{
   string name;
   string number
};

vector<Contact> contacts;


http://www.cplusplus.com/reference/algorithm/sort/
Well the teacher didn't put any restrictions but we haven't studied vectors yet therefore I'm not quite sure how to implement it. Nonetheless I'll try to understand it. Ty
Topic archived. No new replies allowed.