proffreda

C++ Array of Structs

Feb 23rd, 2016
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #define Length 3
  4.  
  5. struct EmployeeStruct {
  6.   char title [20];
  7.   int year;
  8. } employee [Length];
  9.  
  10. void printemployee (EmployeeStruct employee);
  11.  
  12. int main () {
  13.  
  14.   for (int n=0; n < Length; n++) {
  15.     cout << "Enter title: ";
  16.     cin >> employee[n].title;
  17.     cout << "Enter year: ";
  18.     cin >> employee[n].year;
  19.   }
  20.   cout << "\nYou have entered these employees:\n";
  21.   for (int n=0; n<Length; n++)
  22.     printemployee (employee[n]);
  23.   return 0;
  24. }
  25.  
  26. void printemployee (EmployeeStruct employee)
  27. {
  28.   cout << employee.title;
  29.   cout << " (" << employee.year << ")\n";
  30. }
Advertisement
Add Comment
Please, Sign In to add comment