fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct PRODUCT
  5. {
  6. char name[50];
  7. int cost;
  8. };
  9.  
  10. int main()
  11. {
  12. PRODUCT ice_cream[5];
  13. for( int i = 0; i < sizeof ice_cream / sizeof *ice_cream; ++i )
  14. {
  15. puts("input name and cost");
  16. scanf( "%s %d", ice_cream[i].name, &ice_cream[i].cost );
  17. }
  18. for( int i = 0; i < sizeof ice_cream / sizeof *ice_cream; ++i )
  19. printf( "%d : %s %10u\n", i, ice_cream[i].name, ice_cream[i].cost );
  20. return 0;
  21. }
Success #stdin #stdout 0s 3416KB
stdin
a 10
b 20
c 30
d 40
e 50
stdout
input name and cost
input name and cost
input name and cost
input name and cost
input name and cost
0 : a         10
1 : b         20
2 : c         30
3 : d         40
4 : e         50