| | |
build but wont run... hmmm please help.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2007
Posts: 15
Reputation:
Solved Threads: 0
i wrote this program to input 12 intigers (mustuse linked lists), sort it while its being inserted, then take the average, then take out the numbers that are greater then the average and make a new lists, then take a second list of 12 intigers, then lastly merge those 2 lists into one that eliminates duplicates.
the program will build but when i run it (2003 builder) i get 'fatal error' pop up as soon as i press enter after putting in the first intiger. It is very frustrating. There is nothing more specific, just fatal error. Can anyone find the issue? I am a newbie, please be patient with me
the program will build but when i run it (2003 builder) i get 'fatal error' pop up as soon as i press enter after putting in the first intiger. It is very frustrating. There is nothing more specific, just fatal error. Can anyone find the issue? I am a newbie, please be patient with me
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; class node_type //dec of class { public: int num; node_type *next; }; void SortInsert (node_type** head,int data, bool nodeup); int main () { node_type *prev, *current, *current2, *newnode; node_type *head, *head2, *head_merged, *temp; int i, number; float sum, average; sum = 0; head2 = new node_type; head = new node_type; cout << "Please enter 12 integers\n"; for (i=1; i<=12; i++) { cout << i << "=" <<endl << endl; cin >> number; SortInsert (&head, number, 0); } cout << "entered numbers:\n"; current = head; while (current != NULL) { cout << current->num <<endl; sum += current->num; current = current->next; } average = sum/12; cout << "\n The average of the numbers you inputed is " << average << "\n"; //here we remove numbers less then the average. current = head; while(current != NULL) { if (current->num < average) { if (current == head) head = current->next; else prev->next = current->next; } prev = current; current = current->next; } cout << "This is the list after we took out all of the number less than the average \n"; current = head; while(current !=NULL) { cout << current->num <<endl; current = current ->next; } head2 = NULL; cout << "Now please enter 12 more numbers to be merged into the previous list\n"; for (i=1; i<=12; i++) { cout << i << "=" << endl << endl; cin >> number; SortInsert (&head2, number, 0); } cout << "Enterded Numbers: \n"; current = head2; while(current !=NULL) { cout << current->num <<endl; current = current->next; } //here create a new list with data from the first 2 and remove dups. head_merged = NULL; current = head; while (current!= NULL) { SortInsert(&head_merged, current ->num, 1); current = current->next; } current = head2; while(current != NULL) { SortInsert(&head_merged, current ->num, 1); current = current->next; } cout << "The 2 lists merged together, duplicates removed:\n"; current = head_merged; while(current != NULL) { cout <<current->num << endl; current = current->next; } cin >> number; //keep the window open after program runs return 0; } //sorting stufff void SortInsert(node_type** head, int data, bool nodup) { node_type *current, *prev, *newnode; newnode = new node_type; newnode-> num = data; current = *head; while ((current != NULL && current->num <=data)) { if(current->num == data && nodup) return; prev = current; current = current->next; } if(*head == current) { *head = newnode; newnode->next = current; } else if (current == NULL) { prev->next = newnode; newnode->next = NULL; } else { prev->next = newnode; newnode->next = current; } }
Last edited by Ancient Dragon; Jun 21st, 2007 at 6:28 am. Reason: corrected code tags
1. Write some comments in the code.
2. Nice of you to use code tags, did you know that you can also add the language name to it for syntax highlighting.
3. Problem might be that next is not initialized to NULL. So on line 110 after first iteration current is set to junk.
4. To find such errors, you gotta write some traces (couts with values of variables) in the code (or use a debugger like VS or Sun Workshop or CodeBlocks or gdb...)
2. Nice of you to use code tags, did you know that you can also add the language name to it for syntax highlighting.
3. Problem might be that next is not initialized to NULL. So on line 110 after first iteration current is set to junk.
4. To find such errors, you gotta write some traces (couts with values of variables) in the code (or use a debugger like VS or Sun Workshop or CodeBlocks or gdb...)
Last edited by thekashyap; Jun 21st, 2007 at 1:24 am. Reason: Added #4
Are you Agile.. ?
![]() |
Similar Threads
- Pascal : Cant see why program wont run, exits with error. (Pascal and Delphi)
- Dell wont run (Troubleshooting Dead Machines)
- Script wont run on different computer (Python)
- Virus Programming (Assembly)
- my G4 sawtooth 400 wont run dual monitors, at the same time (Apple Hardware)
Other Threads in the C++ Forum
- Previous Thread: MSVC++ 2005: Find The Brightest Pixel..
- Next Thread: My First GUI / Animation
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings struct temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






