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" ;
}
}