Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

putting isdigit(c) into an variable.

Status
Not open for further replies.

dnfrantum

Programmer
Oct 23, 2001
175
US
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 << &quot;This program creates a P&H table to be loaded into the&quot; << endl;
cout << &quot;Ecometry PH-DOLLARS dataset.&quot; << endl;
cout << endl;
cout << endl;
cout << &quot;Please enter the Ship Method that you wish to apply&quot; << endl;
cout << &quot;these shipping charges and <enter>:&quot; << endl;
cin >> ship_method;
cout << &quot;Please enter the zone that you wish to apply to these&quot; << endl;
cout << &quot;charges and <enter>:&quot; << endl;
cin >> zone;
cout << &quot;Please enter the company that you wish to apply these&quot; << endl;
cout << &quot;charges and <enter>:&quot; << endl;
cin >> company;
cout << &quot;Please enter the path where the input file can be found:&quot; << endl;
cin >> in_file;
cout << &quot;Please enter the path where the output file should be placed:&quot; << 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 << &quot; &quot;;
}
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 << &quot;MGR&quot;;
out << setw(92) << setfill(' ');
out.setf(ios::left);
out << &quot;20030905010101&quot;;
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 << &quot; &quot;;
}
}
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 << &quot; &quot;;
}
}
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top