need some help

This is a discussion on need some help within the C++ Programming forums, part of the General Programming Boards category; It was suggested before that you should write a delimiter (space) in the file. Otherwise all the numbers will be ...

  1. #31
    The larch
    Join Date
    May 2006
    Posts
    3,573
    It was suggested before that you should write a delimiter (space) in the file. Otherwise all the numbers will be right after each other.
    out << num1 << " " << num2 << " " << ...

  2. #32
    Registered User
    Join Date
    Jul 2006
    Posts
    25
    i will make that adjustment now. any suggestions on how to get my search at the bottom to only print out the one of the inputs of the terminal information?

  3. #33
    Registered User
    Join Date
    Jul 2006
    Posts
    25
    latest code still no data prints out get press any key to continue after i enter the number 1 to see the first input. I am so fraustrated with this program. Doing a programming class with no instructor near by is terrible.

    I am having these problems with the excercises. man i cant wait for the test. lol I am getting it very slowly so maybe i will be okay.

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <iomanip>
    #include<cassert>
    using namespace std;
    
    class TermInfo
    {
    public:
    	string bldg;
    	char accessCode;
    	int transRate;
    	string termType;
    	int serviceDay;
    	int serviceMonth;
    	int serviceYear;
    	int TermNumber;
    };
    void main()
    {
    	/* int TotalTerm; */
    
    	int const TotalTerm = 2;
    	
        
    	cout << "Enter two sets of data for your terminal entrys today" << "\n";
    	/* cin >> TotalTerm;  */
    	ofstream outFile("afile.txt");
    	assert(outFile.is_open());
        TermInfo info[TotalTerm];
    	
    	for (int i=0; i < TotalTerm; i++)
    	{
    		cout << "Enter Terminal Number (INT):  "  << "\n";
    		cin >> info[i].TermNumber;
    		cout << "Enter Transmission rate (INT):  " << "\n";
    		cin >> info[i].transRate;
    		cout << "Enter terminal type (String):  " << "\n";
    		cin >> info[i].termType;
    		cout << "Enter building terminal is located (String):  " << "\n";
    		cin >> info[i].bldg;
    		cout << "Enter access code to terminal (Char):  " << "\n";
    		cin >> info[i].accessCode;
    		cout << "Enter day of last servicing date (dd) (INT):  " << "\n";
    		cin >> info[i].serviceDay;
    		cout << "Enter month of last servicing date (mm)(INT):  " << "\n";
    		cin >> info[i].serviceMonth;
    		cout << "Enter year of the last servicing date (YYYY) (INT):  " << "\n";
    		cin >> info[i].serviceYear;
    		outFile << info[i].TermNumber << info[i].transRate << info[i].termType << info[i].bldg << info[i].accessCode << info[i].serviceDay << info[i].serviceMonth << info[i].serviceYear;
    	}
    	
        
    	outFile.close();
    
    	/* This section gets value from the closed file  */
    
    	ifstream inFile("afile.txt");
    	
    	
    	if(!inFile)
    	{
    		cerr << "File could not be opened!" << "\n";
    		exit (1);
    	}
        
    	cout << "Enter Terminal number to search for:  " << "\n";
    	int search;
    	cin >> search;
    
    
            TermInfo currentInfo;
    
    	while(inFile >> currentInfo.TermNumber >> currentInfo.transRate 
    	       >> currentInfo.termType >> currentInfo.bldg >> currentInfo.accessCode 
                   >> currentInfo.serviceDay >> currentInfo.serviceMonth 
                   >> currentInfo.serviceYear)
    {
            if(search == currentInfo.TermNumber)
            {
                cout << currentInfo.TermNumber <<  "   " << currentInfo.bldg << "     "  << currentInfo.accessCode << "\n"; 
    			cout << currentInfo.transRate << "     " << currentInfo.termType << "     " << currentInfo.serviceDay << "\n";
    			cout << currentInfo.serviceMonth << "    " << currentInfo.serviceYear << "\n";
    	}	
    	else 
    		cout << "please re run the program"  ;
              
            }
    }

  4. #34
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    you are getting close.
    like anon already said, you have to output some delimiter when writing the record.
    Code:
            outFile << info[i].TermNumber << " " << info[i].transRate << " " << info[i].termType << " " << info[i].bldg << " "<< info[i].accessCode << " " 
                    << info[i].serviceDay << " " << info[i].serviceMonth << " " << info[i].serviceYear << endl;
    as long as you don't input any whitspace when reading the strings it should work.
    if you want to allow whitespace in the strings you will have to write some different delimiter and use getline() to read the data.
    Kurt
    Last edited by ZuK; 07-15-2006 at 09:31 AM.

  5. #35
    Registered User
    Join Date
    Jul 2006
    Posts
    25
    Thanks for all your help. I got it to work now. It seems the small things tend to cause more trouble than the ones you think are harder.

    I appreciate the help guys

  6. #36
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Code:
    void main()
    As already mentioned, this should be int main() . . . .
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21