My 5 digit number turned into a six digit number. Now instead of being an int it became a long and my code no longer works. Can someone review what I have and comment?
My result isn't human readable, so it will probably not help to send it. The code works fine if 'currentvalue' is set to int and the setw(6) is setw(5). But if the values in the stream increment past 5 digits, this doesn't work.
Thanks in advance,
Donald
Code:
/* Donald Frantum */
#include <iostream.h>
#include <ctype.h>
#include <fstream.h>
#include <string>
#include <iomanip.h>
void main()
{
int ship_method = 0;
int zone = 0;
int company = 0;
string in_file;
string out_file;
cout << "This program creates a P&H table to be loaded into the" << endl;
cout << "Ecometry PH-DOLLARS dataset." << endl;
cout << endl;
cout << endl;
cout << "Please enter the Ship Method that you wish to apply" << endl;
cout << "these shipping charges and <enter>:" << endl;
cin >> ship_method;
cout << "Please enter the zone that you wish to apply to these" << endl;
cout << "charges and <enter>:" << endl;
cin >> zone;
cout << "Please enter the company that you wish to apply these" << endl;
cout << "charges and <enter>:" << endl;
cin >> company;
cout << "Please enter the path where the input file can be found:" << endl;
cin >> in_file;
cout << "Please enter the path where the output file should be placed:" << endl;
cin >> out_file;
ifstream zone_chrg_input;
zone_chrg_input.open(in_file.c_str());
ofstream out;
out.open(out_file.c_str());
int c;
int i;
int count[5];
long line_cnt = 0;
long where_i_am = 100;
long range = 0;
int digit_cnt = 0;
long currentVal = 0;
line_cnt = 0;
zone_chrg_input >> currentVal;
while (!zone_chrg_input.eof())
{
if (company < 10)
{
out << setw(2) << setfill('0') << company;
}
if (ship_method < 10)
{
out << setw(2) << setfill('0') << ship_method;
}
else
{
out << ship_method;
}
if (zone < 10)
{
out << setw(2) << setfill('0') << zone;
}
if (range < 100)
{
out << setw(2) << setfill('0') << range << " ";
}
else
{
out << setw(2) << setfill('0') << range << " ";
}
while (line_cnt < where_i_am && !zone_chrg_input.eof())
{
out << setw(6) << setfill('0') << currentVal; //<< endl; for newline
++line_cnt;
zone_chrg_input >> currentVal;
}
range = ++range;
where_i_am = where_i_am + 100;
out << setw(8) << setfill(' ');
out.setf(ios::left);
out << "MGR";
out << setw(92) << setfill(' ');
out.setf(ios::left);
out << "20030905010101" << endl;
out.setf(ios::right);
}
zone_chrg_input.close();
out.close();
}
My result isn't human readable, so it will probably not help to send it. The code works fine if 'currentvalue' is set to int and the setw(6) is setw(5). But if the values in the stream increment past 5 digits, this doesn't work.
Thanks in advance,
Donald