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;
}
Last edited by Ancient Dragon; Dec 15th, 2006 at 1:06 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Offline 21,963 posts
since Aug 2005