C++ Program to Display the Details of Employee Using Structure

In this program, you'll learn to declare structure 'employee' having data member name, age, street and city. Accept data for two employees and display it.

Source Code
using namespace std;

struct employee
    char name[20], street[20], city[20];
    int age;

int main()
    struct employee e[3];
    int i;
    for(i=0; i<3; i++)
        cout<<"Enter Employee's name: ";
        cin>> e[i].name;
        cout<<"Enter age: ";
        cin>> e[i].age;
        cout<<"Enter street: ";
        cin>> e[i].street;
        cout<<"Enter city: ";
        cin>> e[i].city;
    cout<<"\nFollowing are the details of employees:\n\n";
    for(i=0; i<3; i++)
        cout<<e[i].name << ", ";
        cout<<e[i].age << ", ";
        cout<<e[i].street << ", ";
        cout<<e[i].city << "\n";
    return 0;
Enter Employee's name: Rajesh
Enter age: 25
Enter street: SataraRoad
Enter city: Pune
Enter Employee's name: Kamla
Enter age: 22
Enter street: VinodNagar
Enter city: Jalgaon
Enter Employee's name: Dinesh
Enter age: 38
Enter street: ConvexMall
Enter city: Mumbai

Following are the details of employees:

Rajesh, 25, SataraRoad, Pune
Kamla, 22, VinodNagar, Jalgaon
Dinesh, 38, ConvexMall, Mumbai

"Coding Hub - Learn to code" app now available on Google Play Store