Brand new to the board - I am taking an intro course and have been sailing through the programs until this one. It is a distance learning class with an ?instructor? There are 45 programs to write and I am stuck on the 37th one. Here goes:
There is a text file I had to create that has information on computer terminals in a network. There are 100 terminals and the info on the nth terminal is on the nth line of the file. The computer info is terminal type (string), building located in (string), transmission rate (integer), access code (character), and date of last service (month, day, year).
Write a program to read terminal numbers from the keyboard and directly access the line in the file for each terminal by moving the read position directly to that line. The program should retrieve and display the terminal info.
This is Chapter 9 and covers ifstream and ofstream objects as well as additional stream features. So, it is not advanced - did I mention it was an intro course?
I have reworked the code so much...I was getting the terminal info, but now it just hangs before getting to that point (have to control-C to get out). I know it is something simple and I am over thinking the problem. But I can't figure out what it is. A little detailed in my problem explanation I know but what can I say – programming! Any and all help is appreciated.
#include <iomanip> // not used yet
using namespace std;
// ensures the input file is open
// set line length for finding data
const int LINE_LENGTH = 100;
// variable declarations
cout << "\nEnter terminal number: ";
cin >> terminalNumber;
if (terminalNumber > 0 && terminalNumber <= 100)
// find the beginning of the line for that terminal number
readInFile.seekg(terminalNumber * LINE_LENGTH, ios::beg);
// read in terminal information from file
readInFile >> terminalType >> terminalBuilding >> transmissionRate
>> accessCode >> date;
// print terminal information to screen
cout << "\nInformation for computer number: " << terminalNumber
<< "\nType of terminal: " << terminalType
<< "\nis located in the " << terminalBuilding << " building"
<< "\nhas a transmission rate of: " << transmissionRate
<< "\nan access code of: " << accessCode
<< "\nand the last service date was on: " << date;
cerr << "\nTerminal number is invalid."
<< "\nValid numbers are from 1 through 100."
<< "\nTry Again? (Y or N): ";
cin >> response;
while (response != 'N' && response != 'n');