I have an input stream that is populated with prices. I want to strip out the decimal and if the price is less than 5, I want to capture that and pad it with 0's. Here is what I have so far, of which none of it is doing what I described above.
/* 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;
long line_cnt = 0;
long where_i_am = 100;
long range = 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)
{
if (isdigit(c))
{
out << c;
}
if (c == '\n')
{
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";
if (range < 100)
{
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 << " ";
}
}
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 << " ";
}
}
zone_chrg_input.close();
out.close();
}
On lines 70-80 is where I need to add the logic. I think it will be an array, but I am not very good with arrays.
Thanks in advance,
Donald
/* 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;
long line_cnt = 0;
long where_i_am = 100;
long range = 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)
{
if (isdigit(c))
{
out << c;
}
if (c == '\n')
{
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";
if (range < 100)
{
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 << " ";
}
}
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 << " ";
}
}
zone_chrg_input.close();
out.close();
}
On lines 70-80 is where I need to add the logic. I think it will be an array, but I am not very good with arrays.
Thanks in advance,
Donald