this program compiles and gives the following return state/code

Exit code: -1073741819

this is very irritating i would also ask please do not post the output file here this is a challenge from arcanum i just want a working program.

please help me with this program.

this is what i have to do

thanks to all who help me as well

Number Triangles 7
3 8
8 1 0
2 7 4 4
4 5 2 6 5
The above figure shows a number triangle. Write a program that calculates the highest sum of numbers passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the left or diagonally down to the right. In the sample shown above, the route from 7 to 3 to 8 to 7 to 5 produces the highest sum: 30.

Attachments
76 
91 61 
21 57 94 
13 14 32 74 
51 85 08 61 93 
19 47 76 00 91 92 
14 61 70 92 43 00 57 
71 37 88 10 84 90 08 20 
00 28 54 68 42 41 12 40 45 
81 17 39 50 37 10 53 97 21 08 
25 34 05 06 95 08 05 22 38 51 90 
10 90 35 84 36 68 93 49 63 92 00 28 
27 06 98 09 58 00 59 17 12 43 80 82 90 
26 88 87 96 17 67 51 07 33 74 47 30 32 55 
13 81 29 29 53 93 36 67 85 84 31 06 43 70 63 
38 72 82 83 32 41 54 32 97 02 43 44 60 20 58 20 
75 15 49 32 20 23 38 86 13 27 34 37 92 59 30 63 95 
40 16 93 91 43 97 10 85 34 63 09 62 17 94 32 79 01 52 
70 85 23 37 53 68 58 55 98 02 39 93 64 17 16 28 69 43 83 
78 19 54 07 17 03 77 71 66 06 72 83 77 06 68 49 19 75 44 72 
00 86 47 73 14 26 46 93 58 20 93 68 01 67 03 44 59 92 30 31 57 
25 37 40 16 89 38 17 66 30 30 24 22 61 66 68 02 51 04 34 48 41 76 
20 25 03 12 35 45 35 77 60 01 10 32 15 63 64 93 56 15 38 93 37 79 76 
29 44 16 80 91 64 44 20 54 76 63 16 36 36 33 78 98 36 84 23 99 17 15 61 
61 12 52 58 80 99 32 75 30 38 73 96 84 75 96 36 18 91 80 37 10 67 86 59 04 
55 49 67 51 20 72 05 95 47 21 91 14 64 45 90 94 03 38 22 39 25 54 56 87 33 92 
36 47 14 69 08 33 27 88 84 86 67 40 11 79 36 14 78 97 51 84 47 74 07 32 22 91 38 
76 41 07 86 72 24 39 31 50 45 52 78 49 60 75 62 23 82 23 72 81 00 08 46 20 59 49 34 
29 99 50 02 17 41 53 52 45 54 54 35 02 78 54 49 32 19 71 77 32 13 66 64 22 80 07 98 25 
33 28 84 55 99 07 72 42 95 29 45 86 19 39 09 98 10 63 99 91 26 01 50 81 92 76 35 91 80 29 
25 76 65 47 70 91 07 31 67 13 36 66 97 28 50 21 02 18 32 28 99 31 86 73 84 85 94 48 24 95 05 
89 07 53 41 73 25 69 50 67 75 98 85 22 56 53 23 01 29 41 25 30 38 12 47 74 46 63 88 04 87 94 98 
79 93 37 38 96 94 75 95 41 45 69 55 86 83 99 52 62 70 52 63 75 21 46 96 66 72 39 29 97 93 03 45 69 
95 15 25 39 39 48 48 55 95 99 49 72 58 56 91 63 72 38 08 97 67 00 60 91 61 36 68 06 29 87 70 10 92 76 
61 51 38 82 58 90 08 65 61 25 74 66 37 43 45 90 15 61 11 93 07 69 79 85 42 40 96 66 39 26 29 11 94 08 84 
20 14 05 32 48 75 16 41 25 26 16 67 01 28 57 05 96 47 98 56 17 83 33 13 12 60 24 16 15 65 17 86 62 45 36 81 
31 66 45 84 84 34 79 81 67 82 06 15 34 30 54 90 66 10 49 12 53 80 87 28 87 03 11 69 60 21 99 34 00 00 41 45 45 
81 01 95 88 04 53 24 86 45 92 43 71 34 82 41 66 86 76 06 28 30 51 71 17 52 88 37 45 33 59 78 63 22 34 83 68 09 77 
28 83 24 43 42 73 56 50 66 85 07 29 58 42 59 27 50 93 90 73 00 58 12 84 57 47 59 07 85 12 05 79 43 09 37 18 81 16 70 
03 65 93 12 66 56 36 90 57 76 99 26 04 99 36 74 28 70 58 29 25 07 29 89 92 96 03 98 06 20 47 57 17 35 30 12 81 37 22 18 
87 36 97 93 10 78 77 48 32 19 13 14 73 18 31 49 77 33 54 59 74 83 18 91 97 86 88 55 48 06 14 25 92 33 06 64 94 42 84 53 64 
23 78 33 15 56 35 65 20 13 08 13 66 62 81 37 75 46 10 34 19 32 27 86 73 86 97 53 43 66 61 97 22 18 75 49 92 22 57 07 40 14 60 
94 05 10 93 49 12 57 95 81 24 50 83 66 60 27 92 14 17 89 18 81 29 53 79 63 21 86 21 33 80 27 61 77 92 52 15 72 97 77 93 66 71 61 
04 20 14 06 68 42 56 15 65 96 40 94 17 17 01 79 50 96 12 58 14 77 07 73 09 42 48 79 09 04 46 30 17 95 19 89 56 72 80 14 16 23 35 23 
69 96 07 01 73 36 38 31 76 50 08 27 42 87 09 53 99 48 14 90 51 27 91 56 38 81 84 21 91 33 24 37 69 22 92 17 20 86 86 85 55 93 28 33 82 
22 54 03 74 92 17 38 39 44 73 03 50 86 43 39 09 89 44 48 04 61 87 57 25 67 13 72 16 43 83 74 02 57 84 51 98 71 77 38 16 63 36 42 82 43 10 
35 94 45 61 86 14 17 04 17 27 95 05 64 73 77 63 00 78 88 29 32 87 60 91 17 21 94 79 02 75 52 15 40 74 44 68 92 92 37 28 59 65 72 74 46 95 13 
39 28 89 07 47 99 10 75 36 71 96 35 29 24 25 51 67 53 79 21 87 29 85 06 27 09 82 93 62 17 04 12 58 37 15 91 23 18 90 74 68 60 86 76 41 68 81 18 
54 39 42 00 68 70 91 51 44 60 26 43 38 96 76 72 47 75 42 12 73 72 04 52 20 08 39 98 99 09 44 75 41 26 99 97 89 06 63 41 02 72 45 98 01 15 38 34 10 
54 58 31 36 61 80 49 02 07 07 72 16 36 70 81 70 10 90 18 57 45 07 83 00 67 94 25 75 21 72 79 30 52 54 99 85 98 00 42 05 15 44 59 29 55 65 38 63 52 59 
61 05 07 81 26 18 36 27 80 14 77 13 27 66 13 25 58 17 14 00 51 96 53 07 13 08 87 92 87 20 78 49 13 96 32 98 60 12 34 04 12 00 63 48 42 57 45 67 41 59 54 
68 36 20 10 58 75 49 70 64 12 19 79 12 52 21 71 22 14 16 82 88 58 45 74 18 26 21 24 81 72 65 79 46 97 01 39 59 81 75 56 49 35 14 14 98 47 98 95 71 60 44 66 
43 47 84 20 17 22 51 90 72 64 18 66 28 74 41 60 78 53 39 12 67 19 41 06 63 57 74 87 16 09 85 39 37 99 86 27 91 15 21 49 44 23 29 07 62 51 21 58 85 07 21 24 91 
70 11 44 65 33 24 48 83 13 11 18 44 25 45 37 41 29 82 72 10 44 38 11 49 49 97 83 54 48 30 90 49 32 14 82 65 14 51 94 47 64 66 87 37 24 82 06 21 29 63 98 81 12 10 
00 43 31 07 51 59 72 02 25 20 90 19 40 29 32 86 56 41 96 78 95 94 89 49 09 35 21 72 29 73 05 42 15 51 00 65 46 82 67 03 60 37 72 72 04 24 10 89 81 47 83 49 56 96 02 
25 32 45 52 94 34 07 89 56 10 33 01 63 13 04 09 24 42 87 43 98 27 21 59 47 32 03 38 61 51 28 34 16 81 62 09 92 46 03 23 05 56 03 18 73 66 11 66 88 32 07 11 98 23 93 83 
75 88 98 17 73 26 76 50 58 75 53 19 09 67 89 54 67 39 28 77 41 84 91 98 42 07 92 24 55 77 18 75 17 42 76 17 24 91 31 03 14 50 36 51 64 60 92 22 51 61 27 44 97 11 38 53 66 
62 85 71 26 36 75 20 46 04 32 72 29 26 86 38 75 56 83 15 55 57 44 57 92 38 72 26 44 57 45 71 63 05 86 82 50 15 49 94 60 99 17 61 83 71 39 91 60 60 20 59 59 56 80 79 55 05 90 
70 66 98 11 83 68 60 46 26 41 93 26 60 88 68 32 00 57 37 88 86 18 45 24 73 28 18 39 98 32 09 60 63 24 75 37 09 41 68 71 13 91 15 95 77 86 68 33 48 02 96 36 41 24 08 27 90 97 71 
61 17 42 16 13 35 57 94 28 62 74 83 17 95 74 91 50 90 39 70 29 04 46 88 90 62 82 63 13 80 75 09 90 28 34 04 36 54 83 29 92 44 83 78 97 64 38 99 84 38 58 62 81 08 97 19 59 47 23 38 
21 55 51 90 74 14 84 70 66 30 97 18 38 48 15 40 74 53 11 80 99 48 85 48 06 39 38 60 54 84 08 80 40 68 91 41 64 47 98 25 95 15 74 64 80 58 44 70 65 33 99 41 96 40 88 47 70 18 32 46 92 
53 25 47 15 13 41 51 12 93 08 95 68 97 65 36 37 47 72 87 42 20 86 57 79 22 64 93 95 06 21 81 91 23 90 16 43 24 24 76 77 05 75 23 83 11 00 69 27 81 30 25 27 67 33 66 58 94 38 36 55 06 23 
33 72 54 49 80 74 74 40 39 17 29 88 67 90 27 88 65 73 15 76 34 98 69 81 73 44 48 62 43 78 60 36 33 60 96 72 43 10 81 68 26 96 02 63 00 93 58 13 89 03 95 96 78 83 62 49 47 51 65 19 94 45 51 
34 83 82 92 62 31 10 98 67 90 79 49 47 12 50 59 42 74 45 59 06 38 67 22 31 24 98 16 17 87 89 04 73 45 71 73 47 81 81 23 72 50 37 88 12 08 71 23 16 16 33 32 48 10 85 65 04 07 04 64 93 35 96 82 
82 51 60 63 83 48 86 94 95 90 41 27 60 08 19 85 57 79 01 34 94 07 26 50 20 61 94 62 14 65 07 91 72 97 86 73 57 00 42 87 30 60 68 64 21 49 10 21 62 91 88 73 42 55 32 75 10 20 95 54 73 22 16 76 30 
44 89 09 80 24 17 21 45 76 95 88 52 82 16 46 09 48 37 48 20 99 00 77 82 81 37 74 92 66 67 24 23 19 14 65 95 21 33 55 89 18 04 80 40 74 57 18 52 08 93 50 84 96 77 37 23 09 54 48 20 72 61 62 94 14 06 
25 72 07 66 89 88 33 81 08 97 09 11 33 25 98 03 58 16 22 66 74 99 33 81 91 36 30 50 58 66 90 15 67 06 14 43 63 46 34 13 35 67 85 05 29 39 08 19 43 28 67 21 49 53 49 59 08 47 47 40 18 38 68 95 56 25 91 
46 58 45 98 91 12 20 17 23 86 84 96 95 68 61 35 49 63 06 17 31 99 85 45 89 94 91 40 01 49 82 00 09 95 46 69 11 81 54 34 00 21 27 84 90 85 82 49 13 58 59 63 41 48 14 62 09 73 79 61 93 94 59 21 21 37 88 57 
68 75 95 83 24 96 13 61 63 36 86 45 26 16 88 79 39 36 24 50 65 87 38 50 32 29 67 49 21 86 87 36 64 17 98 23 36 09 67 79 78 56 99 76 56 60 49 24 78 30 35 81 76 05 80 96 84 84 42 94 04 86 38 46 02 22 45 33 31 
04 90 59 02 69 73 10 22 55 76 20 11 90 92 36 12 39 97 49 17 77 52 82 16 20 13 94 90 94 49 04 57 60 62 85 06 89 87 31 99 04 82 57 98 67 70 18 97 42 58 29 04 19 92 55 58 14 65 51 36 28 47 44 15 00 41 08 63 23 51 
39 14 53 57 88 00 99 73 42 10 05 09 18 18 11 83 69 84 33 23 55 54 11 07 77 59 88 64 43 48 65 01 47 45 87 68 34 82 20 32 38 81 62 76 65 38 44 76 99 98 82 93 09 60 19 24 43 96 27 45 74 41 03 01 88 27 31 62 81 11 51 
07 55 93 87 63 85 44 01 51 32 62 07 61 80 73 20 21 96 86 60 77 48 25 15 46 08 44 54 64 80 59 04 83 56 83 94 51 59 21 53 14 72 87 97 91 04 17 70 50 07 44 73 29 77 86 67 55 67 37 62 76 48 98 83 78 17 42 38 99 32 56 65 
00 39 39 79 25 81 15 19 91 61 34 92 52 40 12 20 78 45 97 03 79 67 06 81 35 34 13 16 46 15 39 89 73 69 37 21 81 75 97 06 50 62 77 82 71 82 94 22 92 34 70 67 33 87 64 82 26 16 91 63 08 87 64 72 24 12 54 33 60 18 95 60 65 
25 46 49 92 13 29 12 03 42 55 82 73 21 54 63 50 88 25 56 78 89 28 47 72 36 14 63 35 06 44 02 99 85 66 42 98 07 15 23 44 95 03 19 16 48 64 87 35 91 20 14 28 31 29 41 65 22 95 03 62 02 80 42 44 89 17 47 50 08 52 73 76 33 19 
88 55 14 82 13 38 82 29 94 10 85 71 70 78 68 29 82 73 34 47 83 20 03 31 95 87 21 45 76 90 10 61 40 60 29 02 86 44 32 62 95 52 93 61 42 16 89 01 73 79 95 88 16 77 05 93 53 28 18 02 34 04 99 41 67 82 70 19 44 64 29 81 56 59 59 
06 53 10 12 47 88 68 45 49 25 89 92 41 31 67 39 33 40 62 86 21 01 48 78 32 15 39 77 01 58 17 54 20 92 21 83 59 79 06 08 83 82 62 75 67 81 79 86 52 76 41 74 20 16 64 62 43 18 37 95 89 22 89 15 17 39 36 61 81 40 39 74 42 52 29 80 
16 93 15 29 76 19 41 82 08 25 13 95 58 63 57 17 66 08 16 43 17 62 72 24 10 05 90 01 83 90 51 50 85 98 05 04 25 31 93 42 08 83 59 15 85 49 21 94 08 19 16 07 40 22 74 63 95 48 59 10 67 41 16 43 26 69 58 10 22 70 56 04 97 84 41 27 35 
67 84 90 42 98 86 41 12 69 14 84 40 85 26 87 55 41 41 33 42 20 59 14 94 81 17 34 06 65 77 01 22 99 27 89 48 27 03 42 60 46 92 12 01 72 49 86 15 16 73 08 90 02 74 47 69 00 89 13 16 00 63 74 65 15 59 86 60 30 20 76 15 84 39 83 89 04 62 
26 16 83 83 75 81 11 44 08 82 56 17 35 65 08 75 45 85 80 17 95 65 73 67 73 12 06 09 54 64 20 80 90 29 52 74 52 78 82 90 60 66 66 71 14 41 46 65 83 05 45 68 44 03 59 55 29 87 24 90 92 44 97 94 29 31 19 76 77 98 89 11 30 61 38 50 77 86 11 
64 20 52 55 04 77 66 35 72 06 81 44 93 84 97 54 73 57 99 74 45 01 11 50 84 14 09 73 81 67 96 42 80 55 56 45 47 53 02 88 84 31 38 60 60 30 45 49 67 57 17 97 69 92 38 19 64 71 55 59 21 43 20 19 01 50 52 38 48 48 09 43 34 96 04 56 61 48 64 81 
00 75 68 59 60 32 56 96 84 27 47 78 51 79 58 61 92 37 75 51 84 52 40 69 45 60 28 08 93 69 81 93 78 22 41 19 61 21 95 17 55 74 36 00 85 66 67 30 96 09 64 90 61 73 00 74 17 47 64 84 82 41 77 63 82 78 27 30 43 73 36 62 67 67 77 87 62 08 54 26 34 
27 64 52 15 31 49 07 29 47 68 40 82 29 88 14 74 85 20 34 03 17 14 49 86 31 27 92 49 29 80 91 07 19 19 25 07 66 97 5
#include <cstdlib.h>
#include <iostream.h>
#include <fstream.h>
int main()
{
   int num, rows;
   unsigned int maxsum[200][200],best = 0;
    //cout << "it works here: definitions ";
   ifstream infile("INPUT.TXT");
   ofstream outfile("OUTPUT.TXT");
    //cout << "it works here: filestreams ";
   infile >> rows;
   //cout << "it works here: infilestream rows ";
   for(int b = 1; b <= 200; b++){
      maxsum[0][b] = 0;
    //cout << "it works here: first for loop: iter:" << b<<" ";
   for(int r = 1; r <= rows; r++)
   {
      //cout << "it works here: second for loop: iter:"<<r<<" ";
       maxsum[r][0] = 0;
      for(int c = 1; c <= r; c++)
      {
         //cout << "it works here: third for loop: iter:"<<c<<" ";
          infile >> num;
         // cout << num << " ";
         maxsum[r][c] = (maxsum[r-1][c-1] > maxsum[r-1][c]) ?
                        (maxsum[r-1][c-1] + num) :
                        (maxsum[r-1][c]   + num);
         // cout << maxsum[r][c] << " " << maxsum[r-1][c-1] << " " << maxsum[r-1][c] << " ";
      }
      maxsum[r][r+1] = 0;
   }

   for(b = 1; b <= rows; b++){
      if(best < maxsum[rows][b]) best = maxsum[rows][b];
      cout << "it works here: fourth for loop: iter:"<<b<<" ";
      }}
   outfile << best;
   cout << "it works here: last thing";
   return 0;
}

Your coding style is really quite terrible. There is nothing wrong with putting stuff on separate lines to make it easier to read. Easy reading is much better than being cute. For example:

for(int r = 1; r <= rows; r++)
   {
<snip>
   for(b = 1; b <= rows; b++){
      if(best < maxsum[rows][b]) best = maxsum[rows][b];
      cout << "it works here: fourth for loop: iter:"<<b<<" ";
      }}

would be much better something like this. The coding style below makes it immediately clear where the beginning and ending of the blocks are located -- it is not necessary for the programmer to hunt all over the file for the matching braces.

Putting two braces on the same line like you did just looks very sloppy coding.

for(int r = 1; r <= rows; r++)
   {
        for(b = 1; b <= rows; b++)
       { 
            if(best < maxsum[rows][b]) 
               best = maxsum[rows][b];
             cout << "it works here: fourth for loop: iter:"<<b<<" ";
        }
     }

I this this is a correction

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
   int num, rows;
   unsigned int maxsum[200][200] = {0};
   int best = 0;
    //cout << "it works here: definitions ";
   ifstream infile("INPUT.TXT");
   ofstream outfile("OUTPUT.TXT");
    //cout << "it works here: filestreams ";
   infile >> rows;
   //cout << "it works here: infilestream rows ";
   for(int b = 0; b < 200; b++)
   {
		//maxsum[0][b] = 0;
		//cout << "it works here: first for loop: iter:" << b<<" \n";
		for(int r = 1; r < rows; r++)
		{
			//cout << "it works here: second for loop: iter:"<<r<<" ";
			//maxsum[r][0] = 0;
			for(int c = 1; c < r; c++)
			{
				//cout << "it works here: third for loop: iter:"<<c<<" ";
				infile >> num;
				// cout << num << " ";
				maxsum[r][c] = (maxsum[r-1][c-1] > maxsum[r-1][c]) ?
                        (maxsum[r-1][c-1] + num) :
                        (maxsum[r-1][c]   + num);
				// cout << maxsum[r][c] << " " << maxsum[r-1][c-1] << " " << maxsum[r-1][c] << " ";
			}
			maxsum[r][r+1] = 0;
		}

		for(int k = 1; k < rows; k++)
		{
			if(best < maxsum[rows][k]) 
				best = maxsum[rows][k];
			//cout << "it works here: fourth for loop: iter:"<<b<<" ";
		}
	}
	outfile << best;
	cout << "it works here: last thing\n";
	return 0;
}
Comments
Right: SunnyPalSingh

it is not supposed to have a zero in the output file so my problem stands but thanks so much for the format advice i came from basic where everything was on a different line i continue to ask help me fix this so it gives a correct answer

Just out of curiosity what are the restrictions set on solving the puzzle. That is, could you use a tree or stacks or someother structure besides arrays or are you restricted to use of just arrays?

ust out of curiosity what are the restrictions set on solving the puzzle. That is, could you use a tree or stacks or someother structure besides arrays or are you restricted to use of just arrays?

the information provided at the top was all we were given we can use anything just as long as we don't brute force the site to get the answer. so i have as much info as you do.

This article has been dead for over six months. Start a new discussion instead.