fork download
  1. #include<iostream>
  2.  
  3. int main()
  4. {
  5. using namespace std;
  6.  
  7. int sum;
  8.  
  9. int a;
  10. int b;
  11.  
  12.  
  13. cout << "Total number of equips: ";
  14. cin >> a;
  15.  
  16.  
  17. // Allocate a two-dimensional 3x2 array of ints
  18. int** ippArray = new int*[a];
  19. for (int i = 0; i < a; ++i)
  20. {
  21. ippArray[i] = new int[b];
  22. }
  23.  
  24. // fill the array
  25. for (int i = 0; i < a; ++i)
  26. {
  27. cout << "Total number of catches for " << i << "th equip : ";
  28. cin >> b;
  29. cout << "Equip number: " << i+1 << endl;
  30.  
  31. for (int j = 0; j < b; ++j)
  32. {
  33. cout << "Catch number: " << j+1 << endl;
  34. cin >> ippArray[i][j];
  35. ippArray[i][j]; // Why's this here?
  36. }
  37. }
  38.  
  39. // Output the array
  40. for (int i = 0; i < a; ++i)
  41. {
  42. for (int j = 0; j < b; ++j)
  43. {
  44. cout << ippArray[i][j] << " ";
  45. sum = sum + ippArray[i][j];
  46. }
  47.  
  48. cout << endl;
  49. }
  50.  
  51. cout << endl;
  52.  
  53. cout << "All catches of the all equipes: " << sum-3;
  54.  
  55. // Deallocate
  56. for (int i = 0; i < a; ++i)
  57. {
  58. delete[] ippArray[i];
  59. }
  60. delete [] ippArray;
  61.  
  62. // Keep the window open
  63. cin.get();
  64.  
  65. return 0;
  66. }
Runtime error #stdin #stdout #stderr 0s 529920KB
stdin
Standard input is empty
stdout
Total number of equips: 
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc