PLEASE HELP ME FILL UP THE REST. I DONT KNOW WHAT TO PUT INSIDE THE WHILE LOOP
THE FIRST WHILE LOOP:
THE USER SHOULD ENTER THE INVENTORY.TXT WHICH CONTAINS (HAMMER, NAILS AND ITS COST)
SECOND WHILE LOOP:
//USER WILL ENTER OUTPUTFILE.TXT WHICH CONTAINS THE OUTPUT OF THE PROGRAM
int main()
{
cout << "******************************************************************\n";
cout << "This program will create an inventory report where input file has \n";
cout << "the following data dormat (one record per line). \n\n";
cout << "Part_Name Number_Of_Units Unit_Price \n\n";
cout << "Please notice that part name is a single word";
cout << "********************************************************************";
while (!done)
{
//WHAT CONDITION/ STATEMENTS SHOULD I PUT HERE
// THE USER SHOULD ENTER THE INVENTORY.TXT WHICH CONTAINS (HAMMER, NAILS AND ITS COST)
}
cout << "File " << inFile << " Opened successfully and has data in it \n";
ofstream out;
done = false;
string name;
while (!done)
{
//WHAT CONDITION/ STATEMENTS SHOULD I PUT HERE
//USER WILL ENTER OUTPUTFILE.TXT WHICH CONTAINS THE OUTPUT OF THE PROGRAM
}
os << "*********************************************\n";
os << " Inventory Report \n";
os << "*********************************************\n";
os << endl;
double inv_total = 0.0;
ch = ' ';
while((ch = input.peek()) != EOF)
{
string name = "";
int units = 0;
double cost = 0.0;
input >> name;
input >> units;
input >> cost;
os << left << setw(9) << name;
os << right << setfill (' ') << setw(15) << units
<< setfill(' ') << setw(25) << cost
<< setfill (' ') << setw(20) << units * cost;
inv_total+=units * cost;
os << endl;
}
cout << endl << endl << endl;
os << "---------------------------------------------\n";
os << "Inventory TOtal ($) " << inv_total << endl;
os << "---------------------------------------------\n";
out << os.str();
cout << os.str();
cout << "Finished writitng to output file . \n\n";
just psudo code it. only way is to get your hands dirty. lay it out. Note: this code will not work cause its psudo code so don't compile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
//the loop to continue the list of items
while(exit=0)
{
cout<<"product\n"; //ask for
cin>>product;
cout<<"cost\n"; //ask for
cin>>cost;
//then save to txt file \n
//exit while loop menue
cout<<"0 to exit 1 to Add";
cin>>exit;
if(exit > 1)
{
cout<<"error wrong input input";
exit =0;
}
}
//USER WILL ENTER OUTPUTFILE.TXT WHICH CONTAINS THE OUTPUT OF THE PROGRAM
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <sstream>
usingnamespace std;
int main()
{
cout << "******************************************************************\n";
cout << "This program will create an inventory report where input file has \n";
cout << "the following data dormat (one record per line). \n\n";
cout << "Part_Name Number_Of_Units Unit_Price \n\n";
cout << "Please notice that part name is a single word";
cout << "********************************************************************";
ifstream input;
char ch= ' ';
bool done = false;
string inFile = "";
string output, inventory;
while (!done)
{
//WHAT CONDITION/ STATEMENTS SHOULD I PUT HERE
// THE USER SHOULD ENTER THE INVENTORY.TXT WHICH CONTAINS (HAMMER, NAILS AND ITS COST)
}
cout << "File " << inFile << " Opened successfully and has data in it \n";
ofstream out;
done = false;
string name;
while (!done)
{
//WHAT CONDITION/ STATEMENTS SHOULD I PUT HERE
//USER WILL ENTER OUTPUTFILE.TXT WHICH CONTAINS THE OUTPUT OF THE PROGRAM
}
cout << "\n Reading data file .......\n\n";
ostringstream os;
os<< fixed << showpoint << setprecision(2);
os << "*********************************************\n";
os << " Inventory Report \n";
os << "*********************************************\n";
os << endl;
double inv_total = 0.0;
ch = ' ';
while((ch = input.peek()) != EOF)
{
string name = "";
int units = 0;
double cost = 0.0;
input >> name;
input >> units;
input >> cost;
os << left << setw(9) << name;
os << right << setfill (' ') << setw(15) << units
<< setfill(' ') << setw(25) << cost
<< setfill (' ') << setw(20) << units * cost;
inv_total+=units * cost;
os << endl;
}
cout << endl << endl << endl;
os << "---------------------------------------------\n";
os << "Inventory TOtal ($) " << inv_total << endl;
os << "---------------------------------------------\n";
out << os.str();
cout << os.str();
cout << "Finished writitng to output file . \n\n";
input.close();
out.close();
return 0;
}
And for the while loops, tell me what exactly you are trying to do, so we can help you. Check out all of Bucky's tutorials on YouTube, he has a whole series for beginners :)