unknown error at run time urgent help needed

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2006
Posts: 3
Reputation: backstabber is an unknown quantity at this point 
Solved Threads: 0
backstabber backstabber is offline Offline
Newbie Poster

unknown error at run time urgent help needed

 
0
  #1
Dec 14th, 2006
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.
Last edited by backstabber; Dec 14th, 2006 at 11:51 pm. Reason: forgot to tell you what i was trying to do
Attached Files
File Type: cpp triangle.cpp (1.3 KB, 5 views)
File Type: txt input.txt (59.3 KB, 3 views)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,445
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1475
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: unknown error at run time urgent help needed

 
0
  #2
Dec 15th, 2006
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:
  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.
  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
  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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 3
Reputation: backstabber is an unknown quantity at this point 
Solved Threads: 0
backstabber backstabber is offline Offline
Newbie Poster

Re: unknown error at run time urgent help needed

 
0
  #3
Dec 15th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,688
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 265
Lerner Lerner is offline Offline
Posting Virtuoso

Re: unknown error at run time urgent help needed

 
0
  #4
Dec 15th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 3
Reputation: backstabber is an unknown quantity at this point 
Solved Threads: 0
backstabber backstabber is offline Offline
Newbie Poster

Re: unknown error at run time urgent help needed

 
0
  #5
Dec 16th, 2006
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC