954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

unknown error at run time urgent help needed

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 triangle.cpp (1.32KB) input.txt (59.28KB)
backstabber
Newbie Poster
3 posts since Dec 2006
Reputation Points: 10
Solved Threads: 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;
}
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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

backstabber
Newbie Poster
3 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

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?

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 
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.

backstabber
Newbie Poster
3 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You