Help With LList and Listnodes "Hexadecimal Numbers"

Ive been having issues with my hexadecimal converter for my class. Its made with LList and listnodes. As of now my program can add and multiply single digit characters, when I attempt to add more characters to be added or multiplied my answer that is displayed is missing some of the digits. My professor attempted to give me a hint by saying my Temp1 pointer and Temp2 pointers need to be both be rewritten with if else statements to make sure it did not think it was NULL. I am completely lost on how to solve this issue, any thoughts would be greatly appreciated.


Below I have added my "Add" Method which like I said can compute basic 1 digit numbers or characters such as "A" for 10 or "B" for 11 and "1" for "1". My Readbackward method is what im using to convert the hexadecimal numbers using If Else statements.

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
  void LList::Add(){
//Pre:the N.O. LList is valid.
//Post: the N.O. LList is still valid, but the list is added together and
//displayed to the user.

	LList Second;
	LList Total;

	listnode * temp1;
	listnode * temp2;
	element carry;//the number that carries over from addition.
	element sum;//the actual total.
	element leftbehind;//the number that is left behind at the bottom.

	carry = 0;

	Second.ReadBackward();

	temp1 = head;
	temp2 = Second.head;

//this loop is the adding loop to add everything together.
	while((temp1 != NULL)&&(temp2 != NULL)){


		sum = ((temp1->data)+(temp2->data)+carry);

		carry = sum/16;
		leftbehind = sum%16;
		Total.InsertTail(leftbehind);

		temp1 = temp1 -> next;
		temp2 = temp2 -> next;

		}

	Steal(Total);

	Print();

	} 
Topic archived. No new replies allowed.