Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.10 KB | None | 0 0
  1. import std.stdio;
  2. import std.string;
  3.  
  4. struct Human
  5. {
  6.  string name;
  7.  ushort age;
  8. };
  9.  
  10. void print_list(Human[] human_list)
  11. {
  12.  foreach(human; human_list)
  13.    {
  14.     writeln(human.name);
  15.     writeln(human.age);
  16.    }
  17.   writeln("");
  18. }
  19.  
  20. void add_human(Human[] human_list)
  21. {
  22.   ushort age;                  
  23.   string name;
  24.  
  25.   write("Name: ");                          
  26.   readf(" %s", &name);                        
  27.  
  28.   write("Age: ");                            
  29.   readf(" %u", &age);                      
  30.  
  31.   Human tmp_human = {name, age};
  32.   human_list ~= tmp_human;
  33. }
  34.  
  35. int main()
  36. {
  37.   Human[] human_list;
  38.   char choice;
  39.  
  40.    for(;;)
  41.     {
  42.       writeln("A)dd New Human.");
  43.       writeln("P)rint Human List.");
  44.       writeln("Q)uit.");
  45.  
  46.       write("Input: ");
  47.       readf(" %c", &choice);
  48.        
  49.       switch(choice)
  50.        {
  51.          case('A'):
  52.          case('a'): add_human(human_list);
  53.            
  54.          case('P'):
  55.          case('p'): print_list(human_list);
  56.  
  57.          case('Q'):
  58.          case('q'): return 0;
  59.          
  60.          default: break;
  61.       }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement