arrstruct.cpp 611 B

1234567891011121314151617181920212223
  1. // arrstruc.cpp -- an array of structures
  2. #include <iostream>
  3. struct inflatable
  4. {
  5. char name[20];
  6. float volume;
  7. double price;
  8. };
  9. int main()
  10. {
  11. using namespace std;
  12. inflatable guests[2] = // initializing an array of structs
  13. {
  14. {"Bambi", 0.5, 21.99}, // first structure in array
  15. {"Godzilla", 2000, 565.99} // next structure in array
  16. };
  17. cout << "The guests " << guests[0].name << " and " << guests[1].name
  18. << "\nhave a combined volume of "
  19. << guests[0].volume + guests[1].volume << " cubic feet.\n";
  20. // cin.get();
  21. return 0;
  22. }