This article has been dead for over three months
You
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
using namespace std;
int main()
{
int items;
int index; // counter for loops
ifstream infile_weight; // pointer file for weight
ifstream infile_rate; // pointer file for rate
vector <double> weight (6); // vector with 6 elements
vector <double> rate (6);
infile_weight.open("weight.dat",ios::in); // open file for input
infile_rate.open("rate.dat",ios::in);
cout << "How many packages do you want to enter? ";
cin >> items;
// resize to hold # of items user wants to enter
weight.resize(items);
rate.resize(items);
// loop to prompt user and index items
for (index = 0; index <=(items - 1); index++)
{
cout << "Package # " << index + 1 << ":\n";
cout << "How much does your package weigh? ";
cin >> weight[index];
cout << "What is the postage rate? ";
cin >> rate[index];
}
cout.setf(ios::showpoint);
cout.setf(ios::fixed);
cout << setprecision(2);
cout << "Weight" << " " << setw(10) << "Rate" << endl;
// print table
for (index = 0; index <=(items - 1); index++)
{
cout << weight[index] << setw (17) << rate[index] << endl;
}
infile_weight.close(); // closing files
infile_rate.close();
return 0;
}