Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.stdio;
- import std.string;
- struct Human
- {
- string name;
- float peso;
- ushort age;
- };
- void print_list(Human[] human_list)
- {
- foreach(human; human_list)
- {
- writefln("\nNome: %s",human.name);
- writefln("Peso: %0.2f",human.peso);
- writefln("Idade: %d\n",human.age);
- }
- }
- void add_human(Human[] human_list)
- {
- ushort age;
- float peso;
- string name;
- write("\nName: ");
- readf(" %s\n", &name);
- writeln();
- write("Peso: ");
- readf(" %f\n", &peso);
- writeln();
- write("Age: ");
- readf(" %u\n", &age);
- Human tmp_human = {name, peso, age};
- human_list ~= tmp_human;
- }
- void main()
- {
- Human[] human_list;
- char choice;
- do{
- writeln("A)dd New Human.");
- writeln("P)rint Human List.");
- writeln("Q)uit.");
- write("Input: ");
- readf(" %c", &choice);
- switch(choice)
- {
- case('A'):
- case('a'): add_human(human_list);
- break;
- case('P'):
- case('p'): print_list(human_list);
- break;
- case('Q'):
- case('q'):
- break;
- default: writeln("Opção Invalida ..!!!\n");
- }
- }while(choice != 'q' || choice != 'Q');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement