Advertisement
StormWingDelta

Proving A Point

Apr 1st, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. //What looks wrong with this picture?  If you can't see the issue you don't know enough about programming yet.
  2. //Look closely and you'll see what I mean.
  3. #include <iostream>
  4. #include <cmath>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int carrier = 100;
  10.     int num = 20;
  11.     int array[num];
  12.     int array2[num];
  13.     int result[carrier];
  14.    
  15.     cout << "Enter 20 numbers and I will add" << endl;
  16.     cin >> array[carrier];
  17.     cout << "Enter 20 numbers for the second array" << endl;
  18.     cin >> array2[carrier];
  19.    
  20.     cout << "Now adding the numbers" << endl;
  21.    
  22.     result[carrier] = array[carrier] + array2[carrier];
  23.    
  24.     cout <<  result[carrier];
  25.    
  26.    
  27.    
  28.     system("pause");
  29.     return 0;
  30. }
  31.  
  32. //Next lets show a way to fix this.
  33. #include <iostream>
  34. #include <cmath>
  35. using namespace std;
  36.  
  37. int main()
  38. {
  39.     const int carrier = 20;
  40.     const int num = 20;
  41.     int array1[num];
  42.     int array2[num];
  43.     int result[carrier];
  44.    
  45.     for(int T = 0; T < carrier; T++)
  46.     {
  47.         cout << "Enter a number for array one" << endl;
  48.         cin >> array1[T];
  49.         cout << "Enter a number for the second array" << endl;
  50.         cin >> array2[T];
  51.  
  52.         cout << "Now adding the numbers" << endl;
  53.         result[T] = array1[T] + array2[T];
  54.  
  55.         cout <<  result[T] << endl;
  56.     }
  57.    
  58.    
  59.     system("pause");
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement