can't open output file!

I've been trying to compile this code for quite a while now, and I'm still having errors. The code now compiles fine, but it releases no output on the console, and while it creates an output file, the output file does not open. In fact, it says that it is too big for either notepad or Word to open, even though it's supposed to be a simple text file.

This is the INPUT file I start with

1
2
3
4
5
6
7
8
9
John Smith 111111111111 1963 2008 4000 Secretary
Tasha Patov 222222222 1973 2010 3000 Marketing
Francie Oldon 3333333333 1983 2008 4000 Secretary
Tuyet Nguyen 4444444444 1993 2012 43750 Sales
Jan Won 55555555 1964 2008 5000 Manager
Julie Nabong 666666666 1989 2010 45000 Manager
Jack Burnside 777777777 1991 2008 2000 Payroll
Larry Zubun 888888888 1980 2010 1500 Manufacturing
Valla Eide 999999999 1948 1980 9000 President



And here is my code. The program is supposed to take data from the input file and then recalculate their yearly salary with a bonus, and then record the new information in an output file called "ReportFile.txt" :


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
 #include <iostream>
 #include <fstream>
 #include <string>
 #include <cmath>
 #include <iomanip>
 using namespace std;


    int main (void) {

 

    ifstream fin;

    ofstream fout;

 

     

    string Name;

    string SSN;

    int birthYear;

    int empStart;

    int mSalary;

    string jobTitle;

 

    int year;

    int social;

    int age;

    int emp;

    int totalSalary;

    int bonus;

    int yBonus = 0;

    //char yesNo = 'n' ;

    int total = 0;

    string fileName;

     

    cout << "Enter your file: " ;

    cin >> fileName;

    fin.ignore (1000,10) ;

    fin.open (fileName);

 

    fout.open ("ReportFile.txt");

        fout << setw (17)

        << "|Name|" << setw (17)

        << "|SSN|" << setw (17)

        << "|Yearly Salary|" << setw (17)

        << "|Yearly Bonus|"  << setw (17)

        << "|Job Title|"

 

        << endl;

    fout << "-------------------------------------------------------------------------------------" << endl;

 

    while (!fin.eof())

    { //start while

        fin >> Name; 

        fin >> SSN;

        fin >> birthYear;     

        fin >> empStart;

        fin >> mSalary;

        fin >> jobTitle;
         

        age = 2012 - birthYear;

        emp = 2012 - empStart;

        year = mSalary * 12;

        totalSalary = year + (year * 0.10) ;

        bonus =  0;

         

        if (age >= 30 || emp >= 3)

            bonus = year * 0.10;

        else

            bonus = 0 ;

         

        fout

            << setw (17)

            <<  Name << setw (17)

            << SSN << setw(17)

          //  << SSN % 10000 << setw(17)

            << year << setw (17) 

            << bonus << setw (17)

            <<jobTitle << setw (17)            

 

            <<  endl;

 

        total = total + year ;

        yBonus = yBonus + bonus;

      


    } // end while


     


    fout << "Total Salary: " << total << endl;


    fout << "Total Bonus: " << yBonus << endl;


    fout << "Set Precision to 0" << endl;


    fout.close ();

    fin.close();

  

    return 0;

       
}
only line 57 would print something to the console window.

line 61: why do u ignore the first 1000 chars ? this is setting the starting point after all of ur data. also, the 2nd parameter is the delimiting character ' '. putting a number there probably wont do what u'r expecting...

He's doing that before opening the file (¿?)

the output file does not open. In fact, it says that it is too big for either notepad or Word to open, even though it's supposed to be a simple text file.
¿Did you bother to check the size? Your reading loop is incorrect, causing an infinite loop, and just "filling" the output file

So many empty lines...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;

int main (void) {
   ifstream fin;
   ofstream fout;
   string Name;
   string SSN;
   int birthYear;
   int empStart;
   int mSalary;
   string jobTitle;
   int year;
   int social;
   int age;
   int emp;
   int totalSalary;
   int bonus;
   int yBonus = 0;
   //char yesNo = 'n' ;
   int total = 0;

   string fileName;
   cout << "Enter your file: " ;
   cin >> fileName;
   fin.ignore (1000,10) ;

   fin.open (fileName.c_str());
   fout.open ("ReportFile.txt");
   fout << setw (17)
      << "|Name|" << setw (17)
      << "|SSN|" << setw (17)
      << "|Yearly Salary|" << setw (17)
      << "|Yearly Bonus|"  << setw (17)
      << "|Job Title|"
      << endl;
   fout << "-------------------------------------------------------------------------------------" << endl;

   //Don't loop on eof
   //Loop on the reading, or the file condition
//   while (!fin.eof()) { //start while
   while (fin) { //start while
      fin >> Name;
      fin >> SSN;
      fin >> birthYear;     
      fin >> empStart;
      fin >> mSalary;
      fin >> jobTitle;
      age = 2012 - birthYear;
      emp = 2012 - empStart;
      year = mSalary * 12;
      totalSalary = year + (year * 0.10) ;

      bonus =  0;
      if (age >= 30 || emp >= 3)
         bonus = year * 0.10;
      else
         bonus = 0 ;

      fout
         << setw (17)
         <<  Name << setw (17)
         << SSN << setw(17)
         //  << SSN % 10000 << setw(17)
         << year << setw (17) 
         << bonus << setw (17)
         <<jobTitle << setw (17)            
         <<  endl;
      total = total + year ;
      yBonus = yBonus + bonus;
   } // end while

   fout << "Total Salary: " << total << endl;
   fout << "Total Bonus: " << yBonus << endl;
   fout << "Set Precision to 0" << endl;
   fout.close ();
   fin.close();
   return 0;
}

Now what's wrong
1
2
3
4
5
6
7
//Your reading
      fin >> Name;
      fin >> SSN;
      fin >> birthYear;     
      fin >> empStart;
      fin >> mSalary;
      fin >> jobTitle;
An example input
John Smith 111111111111 1963 2008 4000 Secretary
So you are expect for name to get "John Smith", but you just reading "John"
so should i take out like 61 completely? or do i need it?

and when i try to open it, the file is too big to open---and the size is 5.17 MB. i have no idea why the output file is so huge.
What do/did u want line 61 to do ?
Did u try ne555's suggestions ?
Last edited on
Topic archived. No new replies allowed.