Hi i am currently working on a linked list project but am receiving a few errors while doing so that I can't seem to solve. The first error i am getting is an undetermined #ifndef. What im confused about is that I didnt #include a source file in the header.
My second error I am getting is in my main.cpp, where I am getting an error saying " no matching function call to 'List::AddNode(double, double, double,etc)".
I have posted all three of my files in hopes of someone helping me figure out these errors I am receiving, Thank You.
EDIT: Thank you for those who helped me, that has solved my problem but now I am receiving new errors saying
"undefined reference to List::List()',
undefined reference to List::AddNode(double, double, double, double, double, double, double, double)',
undefined reference to `List::PrintList()'".
Main
#include <iostream>
#include <cstdlib>
#include "List.h"
using namespace std;
int main()
{
List Moe;
Moe.AddNode(23.00, 7.00, 12.75, 7.65, 1.00,45.00, 0.18, 50.00);
Moe.PrintList();
}
Header File
#ifndef LIST_H_INCLUDED
#define LIST_H_INCLUDED
#endif LIST_H_INCLUDED
using namespace std;
class List
{
private:
struct node{
double adults, children,costA,costC,dessert,room,tt,deposit;
node* next, *link;
};
typedef struct node* nodePtr;
nodePtr head;
nodePtr curr;
nodePtr temp;
public:
List();
void AddNode(double addAdults,double addChildren, double addCostA, double addCostC,double addDessert, double addRoom, double addTT, double addDeposit);
void PrintList();
};
CPP File
#include <cstdlib>
#include <iostream>
#include "List.h"
using namespace std;
List::List()
{
head = NULL;
curr = NULL;
temp = NULL;
}
void List::AddNode(double addAdults,double addChildren, double addCostA, double addCostC,double addDessert, double addRoom, double addTT, double addDeposit)
{
nodePtr n = new node;
n->next = NULL;
n->adults = addAdults;
//cout >> "Number of Adults: " >> addAdults;
n->children = addChildren;
n->costA = addCostA;
n->costC = addCostC;
n->dessert = addDessert;
n->room = addRoom;
n->tt = addTT;
n->deposit = addDeposit;
if(head != NULL)
{
curr = head;
while(curr -> next != NULL)
{
curr = curr->next;
}
curr->next = n;
}
else
{
head = n;
}
}
void List::PrintList()
{
curr = head;
while(curr != NULL)
{
cout << "Total cost for adult meals: $" << (curr -> adults) * (curr -> costA) << endl;
cout << "Total cost for child meals: $" << ((curr -> children) *(curr -> costA)) * 0.60 << endl;
cout << "Total cost for dessert: $" << ((curr -> adults) + (curr -> children)) * (curr -> dessert) << endl;
cout << "Total food cost: $" <<(curr -> adults) * (curr -> costA) +
(curr -> children) *(curr -> costA) * 0.60 +
((curr -> adults) + (curr -> children)) * (curr -> dessert)<< endl;
cout << "Plus tips and tax: $" <<curr -> tt * ((curr -> adults) * (curr -> costA) +
(curr -> children) *(curr -> costA) * 0.60 +
((curr -> adults) + (curr -> children)) * (curr -> dessert)) <<
" (Does NOT Include Room Fee)" << endl;
cout << "Plus room fee: $" << (curr -> room) << endl;
cout << "Less Deposit: $";
cin >>curr -> deposit;
cout << "" << endl;
cout << "Balance Due: $" << /*FOOD COST*/((curr -> adults) * (curr -> costA) +
(curr -> children) *(curr -> costA) * 0.60 +
((curr -> adults) + (curr -> children)) * (curr -> dessert)) +
/*TIPS & TAX*/ (curr -> tt * ((curr -> adults) * (curr -> costA) +
(curr -> children) *(curr -> costA) * 0.60 +
((curr -> adults) + (curr -> children)) * (curr -> dessert))) +
/*ROOM FEE */ ((curr -> room)) - /*DEPOSIT*/ (curr -> deposit) << endl;
cout << "" << endl;
curr = curr->next;
}
}
You misunderstood the way header guards are used: you need a conditional compile statement to guard the entire content of the header, not just the #define
. Move #endif
to the end of the file, and remove or comment out LIST_H_INCLUDED
at the end:
#ifndef LIST_H_INCLUDED
#define LIST_H_INCLUDED
using namespace std;
class List
{
private:
struct node{
double adults, children,costA,costC,dessert,room,tt,deposit;
node* next, *link;
};
typedef struct node* nodePtr;
nodePtr head;
nodePtr curr;
nodePtr temp;
public:
List();
void AddNode(double addAdults,double addChildren, double addCostA, double addCostC,double addDessert, double addRoom, double addTT, double addDeposit);
void PrintList();
};
#endif /* LIST_H_INCLUDED */