View Single Post
Old Apr 9th, 2006, 2:50 PM   #30
codylee270
Unverified User
 
Join Date: Sep 2005
Posts: 209
Rep Power: 0 codylee270 is an unknown quantity at this point
Please forgive me for posting such a massive amount of code, but i'm in a horrible time crunch, and i tried to quickly come up with something that doesn't do the sort of years w/ company. This is supposed to write to a file. Except after you enter the info, instead of giving you the option to write to a file, the program stalls and fails. I'm clueless, it could be parentheses.

#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#include <iomanip>
#include <vector> 
using namespace std;

void descend_Sort(vector<int>, vector<int>);


int main() 
{
    int i,j,id[10];
    vector<int> years;
    char sex[10];
    float wage[10];
    
    
for(i=0; i<1; i++)
{
	cout << "Please enter the following Employee information:" << endl;
	cout << "\nEmployee ID No: ";
	cin >> id[i];
	cout << "\nEmployee Sex (M or F): ";
	cin >> sex[i];
	while(sex[i] != 'M' && sex[i]!='m' && sex[i]!='F' && sex[i]!='f')
	{
	
                    cout << "Must be M or F. Please retry: ";
                    cin >> sex[i];
    }
                    
	cout << "\nEmployee Numeric Wage: ";
	cin >> wage[i];
	cout << "\nYears with Company: ";
	cin >> years[i];
	cout << endl;
	
}
//vector<int> yearscopy(years);
//descend_Sort(yearscopy, years);

cout << "You have entered:" <<endl;
cout <<"Employee ID       " << "Employee Sex         " << "Numeric Wage        " 
     << "Years with Company" << endl;
cout << "-----------       " << "------------         " << "------------        "
     <<"------------------" << endl;
     
     for(j=0; j<1; j++)
     {
              cout << setw(11) << right << id[j] << "       "
              << setw(12) << char(toupper(sex[j])) << "         " << "$  " << setw(9) << fixed <<
              setprecision(2) << right << wage[j] << "        " << setw(18) << 
              right << years[j] << endl;
     }
     
     cout << "Would you like to write the information to a file? This will overwrite the file."
     << "Would you like to continue? (y/n) : " ;
    char response;
    cin >> response;
	while(response !='N' && response!='n' && response!='Y' && response!='y')
	{
	               cout << "Must enter Y or N: ";
                   cin >> response;
    }
    if( response == 'Y' || response == 'y')
    {
        ofstream file;
        file.open("testfile.txt");
        if(file.fail())
        {
                       cout << "The file was not succesfully opened." << endl;
        }
        else
        {
           file <<"Employee ID       " << "Employee Sex         " << "Numeric Wage        " 
           << "Years with Company" << endl;
           file << "-----------       " << "------------         " << "------------        "
           <<"------------------" << endl;
     
     for(j=0; j<1; j++)
     {
              file << setw(11) << right << id[j] << "       "
              << setw(12) << char(toupper(sex[j])) << "         " << "$  " << setw(9) << fixed <<
              setprecision(2) << right << wage[j] << "        " << setw(18) << 
              right << years[j] << endl;
     }
     file.close();
     }
     
     cout << "The file has been written successfully." << endl;
     }
     else
     {
         cout << "The file has not been written." << endl;
     }       
     
    
    system("PAUSE");
    return 0;
}

PLEASE FORGIVE ME FOR THE AMOUNT. It's the best i could do.
codylee270 is offline   Reply With Quote