Need help Compiling

Hi im not sure what im doing wrong. I have a project due and cant figure out what the bug is. Its suppose to be a simple linked list project with the basic

[A} add course
[B] remove Course
[C] display course
[D] Quit

this is what i have below so far im using CodeBlocks to run it


*******************************************

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <string>
#include <iomanip>
#include <random>
#include <ctime>
#include <fstream>
#include <Windows.h>
using namespace std;

#include "Q4.h";

int main()
{

	int Courseid;
	char selection;


	course *object1 ;
	course *addCourse;
	course *removeCourse;


	cout << "[A] Add a course \n" << "[B] Delete a course \n" << "[C] Display all course \n" << "[D] Quit \n";
	cin >> selection;

	while (selection == 'A' || selection == 'a' || selection == 'B' || selection == 'b' || selection == 'C' || selection == 'c')
	{

		switch (selection)
		{
		case 'A' | 'a':
			cout << "Enter a course Id: ";
			cin >> Courseid;
			object1 -> add(Courseid);
			break;

		case 'B' | 'b':
			cout << "Enter course id to delete: ";
			cin >> Courseid;
			object1->Delete(Courseid);
			break;

		case 'C' | 'c':
			object1->dispaly();
			break;

		}
		cout << "[A] Add a course \n" << "[B] Delete a course \n" << "[C] Display all course \n" << "[D] Quit \n";
		cin >> selection;
	}


cout<<endl;
	cout << "GOODBYE"<<endl<<endl;

	return 0;
}



******************************************************

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class course_node
{
unsigned int course_id;


public:
course_node *next;
  
course_node()
{
course_id = INT_MIN;
next = NULL;
}
  
void setid(int id)
{
course_id = id;
}
int getid()
{
return course_id;
}
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class course
{

public:
course()
{
head = NULL;
}

void Add(int id)
{
course *obj = new course_node();
obj->setid(id);

if(head == NULL)
{
head = obj;
}
else
{
obj->next = head;
head = obj;
}

}

int Delete(int id)
{
course_node *temp;
if(head == NULL)
{
cout<<"Empty List";
return 0;
}

if(head->getid() == id)
{
temp = head;
head = head->next;
free(temp);
}
else
{
course_node *prev = head;
while(prev->next->getid() != id && prev->next!=NULL)
prev = prev->next;

// Check if node really exists in Linked List
if(prev->next == NULL)
{
printf("\n Given node is not present in Linked List");
return 0;
}

// Remove node from Linked List
prev->next = prev->next->next;
}
return 1;
}

void dispaly()
{
if(head == NULL){
cout <<"List is empty";
return;
}


course_node *temp = head;
while(temp != NULL)
{

cout<<temp->getid()<<"\n";
temp = temp->next;
}

}

private:
course *head;

};
Last edited on
Hi,
I have a project due and cant figure out what the bug is

Use break points. They stop you code at certain places so you can look at the bits and pieces. Debugging is an almost separate art from coding :(

long and drawn out:
http://wiki.codeblocks.org/index.php?title=Debugging_with_Code::Blocks
quick and dirty:
https://www.youtube.com/watch?v=6CGH9Z19dS8

thanks
Your title says that you need help compiling. I assume by this, you mean that your code won't compile?

If so, it would help if you actually told us what the compiler errors are.
Topic archived. No new replies allowed.