I really need help with this guys. This compiles and runs but does not give me the right output.
tfile.data:
Seth 19 1.7
Austin 20 1.8
Michael 21 1.9
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream fin;
fin.open ("tfile.data");
if (fin.fail())
{
cout <<"ERROR";
exit(1);
}
struct EMP
{
string name;
int age;
double height;
} emp;
struct LISTNODE
{
EMP emp;
LISTNODE *nxt;
LISTNODE (EMP emp1, LISTNODE *nxt1=NULL)
{
emp = emp1;
nxt = nxt1;
};
};
LISTNODE *head = NULL;
string number;
while (fin >> number)
{
head = new LISTNODE(emp , head);
}
LISTNODE *ptr = head;
while ( ptr != NULL)
{
cout << ptr->emp.name<<endl;
cout << ptr->emp.age<<endl;
cout << ptr->emp.height<<endl;
ptr = ptr->nxt;
}
return 0;
}