having runtime problems with program

This is a discussion on having runtime problems with program within the C++ Programming forums, part of the General Programming Boards category; when I run this problem it is supposed to loop so that each time it finished each case, it re--states ...

  1. #1
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901

    having runtime problems with program

    when I run this problem it is supposed to loop so that each time it finished each case, it re--states the switch. When I do switch two however, when it is done it doesn't re-state the case output. I think it is something with the ReportOutput() function. Also, I ma trying to get it to sort the output by reference number, but it doesn't seem to output like I expected. I have no Idea how to do it, can you please help.
    Code:
        ////////////////////
       //Daniel Pritchett//
      //   COP 1220     //
     //   11-2-02      //
    ////////////////////
    /*
    This program will first ask the user for the term, then it will present 3 choices
    to pick from.  Either imput the information to a file, output the information
    from the first file to a report, or quit.  This all is looped so that when the user is
    finished with one choice, they will be able to re-chose again.
    */
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <iomanip>
    
    
    using namespace std;
    
    void OutputInfo(ofstream & outFile1, string & SSN, string & LastName, string & FirstName, string & semester,
    				string & Email, int & choice, int & students, int & ReferenceNum, int RefNum[]);
    void ReportOutput(ifstream & InFile, ofstream & outFile2, string SSN, string LastName, string FirstName, 
    				  string & semester, string & Email, int choice, int students, int ReferenceNum, int RefNum[]);
    
    
    int main ()
    {
    
    	string SSN, LastName, FirstName, semester, Email ;
    	int choice, students, ReferenceNum;
    	int RefNum[3];
    	
    	RefNum[0] = 111111;
    	RefNum[1] = 222222;
    	RefNum[2] = 333333;
    
    	ofstream outFile1;
    	ofstream outFile2;
    	ifstream inFile;
    
    	outFile1.open("a:sdntnfo.dat", ios::out);
    	inFile.open("a:sdntnfo.dat", ios::in);
    	outFile2.open("a:Record.txt", ios::out);
    
    	cout << "Please enter the Class term: ";
    	cin >> semester;
    	//heading
    	outFile2 << setw(6) << "Introduction to C"
    			<< setw(5) <<"\nTerm:" << semester;
    
    	//loops so that the user can re-chose what operation they would like to do.
    	do
    	{
    		cout << "\nWould you like to\n1: Enter Student information\n"
    		<<"2: Read from file and create report"
    		<< "\n3: Quit\n";
    	cin >> choice;
    	switch(choice)
    	{
    		//outputs the first file, student database
    	case (1):
    		OutputInfo(outFile1, SSN, LastName, FirstName, semester, 
    			Email, choice, students, ReferenceNum, RefNum);
    		break;
    
    		//generates reference number organized file
    	case (2):
    		
    		ReportOutput(inFile, outFile2,  SSN,  LastName,  FirstName, 
    				   semester,  Email, choice,  students,  ReferenceNum,  RefNum);
    	
        break;
    
    	//quits
    	case(3):
    		exit(0);
    
    	//default, exits switch and displays switch options 
    	default:
    		cout << "\nYou did not enter a valid choise, please enter correct choice!";
    		break;
    	}
    	}
    	while(choice != 3);   //end of do...while statemet
    
    	outFile1.close();
    	inFile.close();
    	outFile2.close();
    
    	return 0;
    }
    
    void OutputInfo(ofstream & outFile1, string & SSN, string & LastName, string & FirstName, string & semester,
    				string & Email, int & choice, int & students, int & ReferenceNum, int RefNum[])
    {
    
    	cout << "\nHow many students are you entering?";
    		cin >> students;
    		while(students != 0)
    		{
    
    		cout << "\nEnter the student's nine digit ID number: ";
    		cin >> SSN;
    		outFile1 << SSN;
    		cout << "\nEnter the student's First and Last Name: ";
    		cin >> FirstName >> LastName;
    		outFile1 << " " << LastName << " " << FirstName;
    		cout << "\nEnter the student's e-mail@mdcc.edu: ";
    			cin >> Email;
    			outFile1 << " " << Email;
    		cout << "\nEnter the student's Reference number: "
    			 <<"(note, only 111111, 222222, and 333333 are valid.\n)";
    		cin >> ReferenceNum;
    
    		//tests to see if number is correct
    		while((ReferenceNum!=RefNum[0]) && (ReferenceNum!=RefNum[1]) && (ReferenceNum!=RefNum[2]))
    		{
    			cout << "\nYou have entered an invalid number, please enter a correct one: ";
    			cin >> ReferenceNum;
    		} 
    		outFile1 << " " << ReferenceNum << endl;
    		
    		students--;
    		}
    		
    
    }
    
    
    void ReportOutput(ifstream & inFile, ofstream & outFile2, string SSN, string LastName, string FirstName, 
    				  string & semester, string & Email, int choice, int students, int ReferenceNum, int RefNum[])  //this function I seem to have problems with
    {	
    	outFile2 << "\n\n\nReference Number  " << RefNum[0] << endl;
    	outFile2 << "\n\n\nSSN" << right << setw(20) << right << setw(20) << "Last"
    			<< right << setw(20) << "First  " << right << setw(20) << "E-mail@mdcc.edu\n";
    	
    	outFile2 << "\n\n\nSSN" << right << setw(20) << right << setw(20) << "Last"
    			<< right << setw(20) << "First  " << right << setw(20) << "E-mail@mdcc.edu\n";
    	while (!inFile.eof())
    		{
    		inFile >> SSN >> LastName >> FirstName >> Email >> ReferenceNum;
    
    	if(ReferenceNum==RefNum[0])
    		{
    		outFile2 << right << SSN << right << setw(17) << LastName << right 
    			 << setw(16) << FirstName << right << setw(20) << Email;
    		break;
    		}
    		}
    	inFile.seekg(0, ios::beg);
    
    	int n;
    	for(n = 0; n!=40; n--)
    	{outFile2 << "\n";}
    
    		outFile2 << "Reference Number" << RefNum[1] << endl;
    		outFile2 << "\n\n\nSSN" << right << setw(20) << right << setw(20) << "Last"
    			<< right << setw(20) << "First  " << right << setw(20) << "E-mail@mdcc.edu\n";
    
    	while (!inFile.eof())
    		{
    	inFile >> SSN >> LastName >> FirstName >> Email >> ReferenceNum;
    
    	if(ReferenceNum==RefNum[0])
    		{
    		outFile2 << right << SSN << right << setw(17) << LastName << right 
    			 << setw(16) << FirstName << right << setw(20) << Email;
    		break;
    		}
    		}
    	inFile.seekg(0, ios::beg);
    
    	for(n = 0; n!=40; n--)
    	{outFile2 << "\n";}
    		outFile2 << "Reference Number" << RefNum[2] << endl;
    		outFile2 << "\n\n\nSSN" << right << setw(20) << right << setw(20) << "Last"
    			<< right << setw(20) << "First  " << right << setw(20) << "E-mail@mdcc.edu\n";
    
    	while (!inFile.eof())
    		{
    		inFile >> SSN >> LastName >> FirstName >> Email >> ReferenceNum;
    
    	if(ReferenceNum==RefNum[0])
    		{
    		outFile2 << right << SSN << right << setw(17) << LastName << right 
    			 << setw(16) << FirstName << right << setw(20) << Email;
    		break;
    		}
    		}
    }

  2. #2
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    sry for asking I am jsut going crazy.

  3. #3
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    a friend pointed out the problem
    I had
    Code:
    for(n = 0; n!=40; n--)
    like an idiot lol

    I can't keep making mistakes like this.

  4. #4
    UNBANNED OneStiffRod's Avatar
    Join Date
    Jan 2002
    Posts
    669
    Code:
    int n;
    	for(n = 0; n!=40; n--)
    	{
    		cout<<"For loop "<<n<<endl;
    		outFile2 << "\n";}
    You just beat me, I was about to post this change to your for loop in ReportOutput();
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with DLLEXPORT while updating a program
    By pirata in forum C++ Programming
    Replies: 3
    Last Post: 09-05-2008, 02:00 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. Shell output into program during runtime
    By evilkillerfiggi in forum Linux Programming
    Replies: 3
    Last Post: 08-03-2006, 11:50 AM
  4. GPA Program Problems
    By Clint in forum C Programming
    Replies: 3
    Last Post: 04-28-2005, 11:45 AM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM

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