Thread: Error checking....

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    16

    Question Error checking....

    I have this code where I read in a file with a getline to get the originaly balance of a checkbook type document. After that, the .txt.file is set up to read the date, debit or credit transaction type, amount, description of credit/debit. I keep getting an error dealing with the 'Entry.' parts of my code. Not sure what the problem is. Can someone take a look and see if they know whats going on. Is something messed up with my code somewhere. There are one or two more minor errors something to do with the action == part of the code. Any help would be great. Thanks


    Code:
    #include <iostream>
    #include <iomanip>
    #include <string>
    #include <fstream>
    
    using namespace std;
    
    typedef struct Entry
    {
    	string date, action;
    	float amount;
    	string descript;
    }Entry;
    
    int main()
    {
    	string name;
    	float balance;
    
    	ifstream fin;
    	ofstream fout;
    
    	cout << "enter the name of the Checkbook filename: " << endl;
    
    	cin >> name;
    
    	fin.open(name);
    
    	fin >> balance;
    
    	while (!fin.eof())
    	{
    		fin >> Entry.date >> Entry.action;
    		fout << Entry.date << Entry.action;
    
    		if (action == "credit")
    		{
    			fin >> Entry.amount;
    
    			fout << Entry.amount;
    
    			balance = balance + Entry.amount;
    
    		}
    
    		else if (action == "debit")
    		{
    			fin >> Entry.amount;
    
    			fout << Entry.amount;
    
    			balance = balance - Entry.amount;
    
    		}
    
    		getline(fin, descript);
    
    		fout << descript;
    	}
    
    	fout << balance;
    
    }//end main

  2. #2
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    Try changing the name of Entry

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    In C++, you don't need the typedef part when defining a struct. Do it like you would a class:
    Code:
    struct Entry
    {
    // ...
    };
    You then have to make a variable of the type Entry, just like you have variables of the type string, float, ifstream and ofstream. Give that variable a name, then access the properties of that instance with variableName.propertyName (e.g. myEntry.action). That should solve your errors with getline and operator==.

Popular pages Recent additions subscribe to a feed