Because my last post was sooo long, it was suggested that I start a new thread.
The following code isn't returning the values that I expect:
sample input data...
4000
4007
4029
4050
4072
4093
4115
4136
4157
4179
4200
4222
4243
4265
4286
4307
answers to prompts...
shipmethod 43
zone 02
company 00
filename myinfile
output myoutfile
What I am expecting...
This is UPS zone charge table. It contains all the charges per pound for zone 02.
What I need is for it to read in the file myinfile, put the incrementing header '00420201 ' and the footer 'MGR 20030901010101 and 92 trailing spaces' after every 100 lines read into the myoutfile. The header should only increment the last 4 digits, padded with spaces. I can provide an example offline if necessary.
Thanks in advance,
Donald
The following code isn't returning the values that I expect:
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;
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 < 10)
{
out << setw(2) << setfill('0') << range << " ";
}
line_cnt = 0;
while ( (c = zone_chrg_input.get() ) !=EOF )
{
while (line_cnt <= where_i_am)
{
i = 0;
for(i = 0; i < 5 && isdigit(c) && c != '\n'; i++)
{
count[i] = c;
}
out << setw(5) << setfill('0') << count[i];
line_cnt = ++line_cnt;
}
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";
out.setf(ios::right);
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 < 10)
{
out << setw(2) << setfill('0') << range << " ";
}
else
{
out << setw(2) << setfill('0') << range << " ";
}
}
zone_chrg_input.close();
out.close();
}
sample input data...
4000
4007
4029
4050
4072
4093
4115
4136
4157
4179
4200
4222
4243
4265
4286
4307
answers to prompts...
shipmethod 43
zone 02
company 00
filename myinfile
output myoutfile
What I am expecting...
This is UPS zone charge table. It contains all the charges per pound for zone 02.
What I need is for it to read in the file myinfile, put the incrementing header '00420201 ' and the footer 'MGR 20030901010101 and 92 trailing spaces' after every 100 lines read into the myoutfile. The header should only increment the last 4 digits, padded with spaces. I can provide an example offline if necessary.
Thanks in advance,
Donald