linked list and classes.... whaaaat??!!

So Im working on my final project. aaaaand it is not working. my code worked before but it seems like it decided to stop working. I have to create linked list but the program crashes at right when it gets to
EmpPosition *temp = new (EmpPosition). I have no idea of what Im doing wrong... help, in the name of Odin, heeelp!!

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
 system("cls");
		cout << "Position ID#:\n\tThe ID number is determined by the first letter "
			<< "of a position \nfollowed by a three digit number. For example:\n\n";
		cout << setw(5) << "Position ID# \t Positions" << endl
			<< "P100\t\tProfessor" << endl
			<< "O100\t\tFull-time office" << endl
			<< "S100\t\tPart-time office (students only)\n\n" << endl;

		EmpPosition *temp = new (EmpPosition);
		cout << "Enter Postion ID:  ";
		cin >> temp->posID;
		if (toupper(temp->posID[0]) == 'P') // positions with salaries
		{
			cin.ignore();
			cout << "Enter Description: ";
			getline(cin, temp->posDesc);	
			cout << "Enter Institution ID: ";
			getline(cin, temp->instID);
			cout << "Enter Salary: ";
			cin >> temp->salary;
		
			temp->totalPositions++; //static variable
			temp->next = head;
			head = temp;
		}
		else //for positions with wages 
		{
			cout << "Enter Description: ";
			getline(cin, temp->posDesc);	
			cout << "Enter Institution ID: ";
			getline(cin, temp->instID);
			cout << "Enter Hourly Wage: ";
			cin >> temp->hrlyWage;
			cout << "Enter Number of Hours: ";
			cin >> temp->hours;
			temp->totalPositions++;

			temp->next = head;
			head = temp;			
		}
Last edited on
also I get an error that says string subscript out of range when it crashes... help.. anybody...
What does the constructor of EmpPosition look like? The error suggests you are accessing out of bounds on a string, probably in there somewhere.
Thanks for the response yeah the problem was there. I had posID[0] = '' as if it was an array.. thanks a lot

Topic archived. No new replies allowed.