944,198 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1117
  • C++ RSS
Dec 14th, 2006
0

unknown error at run time urgent help needed

Expand Post »
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.
Attached Files
File Type: cpp triangle.cpp (1.3 KB, 9 views)
File Type: txt input.txt (59.3 KB, 5 views)
Last edited by backstabber; Dec 14th, 2006 at 11:51 pm. Reason: forgot to tell you what i was trying to do
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
backstabber is offline Offline
3 posts
since Dec 2006
Dec 15th, 2006
0

Re: unknown error at run time urgent help needed

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:
C++ Syntax (Toggle Plain Text)
  1. for(int r = 1; r <= rows; r++)
  2. {
  3. <snip>
  4. for(b = 1; b <= rows; b++){
  5. if(best < maxsum[rows][b]) best = maxsum[rows][b];
  6. cout << "it works here: fourth for loop: iter:"<<b<<" ";
  7. }}

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.
C++ Syntax (Toggle Plain Text)
  1. for(int r = 1; r <= rows; r++)
  2. {
  3. for(b = 1; b <= rows; b++)
  4. {
  5. if(best < maxsum[rows][b])
  6. best = maxsum[rows][b];
  7. cout << "it works here: fourth for loop: iter:"<<b<<" ";
  8. }
  9. }

I this this is a correction
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int num, rows;
  8. unsigned int maxsum[200][200] = {0};
  9. int best = 0;
  10. //cout << "it works here: definitions ";
  11. ifstream infile("INPUT.TXT");
  12. ofstream outfile("OUTPUT.TXT");
  13. //cout << "it works here: filestreams ";
  14. infile >> rows;
  15. //cout << "it works here: infilestream rows ";
  16. for(int b = 0; b < 200; b++)
  17. {
  18. //maxsum[0][b] = 0;
  19. //cout << "it works here: first for loop: iter:" << b<<" \n";
  20. for(int r = 1; r < rows; r++)
  21. {
  22. //cout << "it works here: second for loop: iter:"<<r<<" ";
  23. //maxsum[r][0] = 0;
  24. for(int c = 1; c < r; c++)
  25. {
  26. //cout << "it works here: third for loop: iter:"<<c<<" ";
  27. infile >> num;
  28. // cout << num << " ";
  29. maxsum[r][c] = (maxsum[r-1][c-1] > maxsum[r-1][c]) ?
  30. (maxsum[r-1][c-1] + num) :
  31. (maxsum[r-1][c] + num);
  32. // cout << maxsum[r][c] << " " << maxsum[r-1][c-1] << " " << maxsum[r-1][c] << " ";
  33. }
  34. maxsum[r][r+1] = 0;
  35. }
  36.  
  37. for(int k = 1; k < rows; k++)
  38. {
  39. if(best < maxsum[rows][k])
  40. best = maxsum[rows][k];
  41. //cout << "it works here: fourth for loop: iter:"<<b<<" ";
  42. }
  43. }
  44. outfile << best;
  45. cout << "it works here: last thing\n";
  46. return 0;
  47. }
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
Ancient Dragon is offline Offline
21,963 posts
since Aug 2005
Dec 15th, 2006
0

Re: unknown error at run time urgent help needed

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
backstabber is offline Offline
3 posts
since Dec 2006
Dec 15th, 2006
0

Re: unknown error at run time urgent help needed

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?
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Dec 16th, 2006
0

Re: unknown error at run time urgent help needed

Quote ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
backstabber is offline Offline
3 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Sorting from file
Next Thread in C++ Forum Timeline: Adding binary values from a file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC