Click here to Skip to main content
15,891,881 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++


#include <iostream>
#include <string>
using namespace std;
struct Person
{
char name[10][10];
int cellnumber[10][10];
};
int main()
{
Person a;
int num;


cout << "Enter the number of people you want to save" << endl;
cin >> num;
cout << "Enter the name of Person" << endl;

for (int i = 0; i < 2; i++)

for(int j = i+0; j > a.name[i][j];




cout << "Enter the cellphone number of person you want to save" << endl;


for (int i = 0; i < 2; i++)

for (int j = 0 + i; j < i; j++)


cin >> a.cellnumber[i][j];






cout << "The numbers saved in phonebook are" << endl;
cout << "Name:" << "\t" << a.name << "\t" << "Number" << "\t" << a.cellnumber << endl;

}

What I have tried:

I tried using for loop as well as while loop and creating 2D arrays but it doesnot works.
Posted
Updated 28-Feb-20 7:47am

Instead of creating a struct containing two arrays, create a struct that contains a name and a number, then create an array of those:
C++
typedef struct _Person
    {
    char Name[100];
    char CellNumber[14];
    } Person;
Person people[10];

int main()
    {
    ...
    for (int i = 0; i < 9; i++)
       {
       cin >> people[i].Name;
       cin >> people[i].CellNumber;
       }
    ...
    }
 
Share this answer
 
v2
Hey man, it is C++...
Try
C++
#include <iostream>
#include <string>
#include <vector>
using namespace std;


struct Person
{
  string name;
  string cellnumber;
};

int main()
{
  vector<Person> vp;
  int num;

  cout << "Enter the number of people you want to save" << endl;

  cin >> num;

  for ( int n=0; n<num; ++n)
  {
    Person p;
    cout << "Enter the name of Person" << endl;
    cin >> p.name;
    cout << "Enter the cellphone number of person you want to save" << endl;
    cin >> p.cellnumber;
    vp.push_back(p);
  }

  cout << "The numbers saved in phonebook are" << endl;
  for (const auto & p : vp)
    cout << "Name:" << "\t" << p.name << "\t" << "Number" << "\t" << p.cellnumber << endl;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900