Limitless profile info in address book?
Code:
#include <iostream>
#include <string>
using namespace std;
struct user
{
string name;
string address;
string phone;
};
void open_entry(user profile[], int c);
void add_entry(user profile[], int &i, int entry[])
{
std::cout << "=====ADD NEW ENTRY=====\n\n";
std::cout << "Name: ";
std::getline(cin,profile[i].name);
std::cout << "Address: ";
std::getline(cin,profile[i].address);
std::cout << "Phone number: ";
std::getline(cin,profile[i].phone);
entry[i];
i++;
}
void browse_entry(user profile[],int i, int entry[])
{ std::cout << "=====BROWSE ENTRY=====\n\n";
std::cout << "Total entries: " << i << endl;
for (int k=1;k<entry[i];k++)
{
std::cout << k << ". " << profile[k-1].name << endl;
}
std::cout << "Select entry (1 to " << i << " )\n";
int list;
std::cin >> list;
std::cout << endl << endl;
for (int i=0;i<10;i++){
if(list == entry[i])
{
int c = entry[i];
open_entry(profile,c);
}
}
}
void open_entry(user profile[], int c)
{
std::cout << "Name: " << profile[c-1].name << endl;
std::cout << "Address: " << profile[c-1].address << endl;
std::cout << "Phone number: " << profile[c-1].phone << endl;
}
int main()
{
bool exit_main(false);
int i=0;
user profile[10];
int entry[10] = {1,2,3,4,5,6,7,8,9,10};
do{
std::cout << "=====MAIN=====\n";
std::cout << endl;
std::cout << "Select option: \n";
std::cout << "1. Add new entry \n";
std::cout << "2. Browse entry list \n";
std::cout << "3. Exit \n";
std::cout << endl;
int option;
std::cin >> option;
std::cin.ignore();
switch(option)
{
case 1:
add_entry(profile, i,entry);
break;
case 2:
browse_entry(profile, i,entry);
break;
case 3:
exit_main = true;
std::cout << "Exiting...\n";
break;
default:
std::cout << "Invalid option. \n";
}
}
while(!exit_main);
}
Right now I can only think of just putting a limited number of profiles. Is it possible to make it limitless, letting the user to add as many profiles as he wants?