Aligning with arrays.

My code reads data of a text file. I am suppose to have do the calculations and have it save to an output file with proper alignment ( left justified, center and right justified)

I need help with the aligning.

#include <iostream>
#include<string>
#include<fstream>

using namespace std;

int main()

{


/*this is an array!*/
string item[10] = {" "}; //ten items
double total[10] = {0.0}; //ten totals
double quantity[10]= {0}; //ten quantity
int i = 0;
double grandtotal = double();
double totalinv= double();



ifstream in;
in.open("input.txt");//opening file later

if(in.fail()) //checking for error in file as in no file found
cout << "file doest work";
if(in.bad()) //checking if file is corrupt
cout << "not found";

while(!in.eof()) //while the file is not done
{


in >> item[i] >> quantity[i] >> total[i];
grandtotal= quantity[i] * total[i]; //calculates the total for the specific product

totalinv += grandtotal; // adds up all the totals
i++;

}

for(int k=0; k<i; k++)
{
cout << item[k] << " " << quantity[k] << " cost: " << total[k] << endl;//showing it
}

cout << "\n\nGrand total of inventory is : " << totalinv<<endl;



system("pause");
in.close();








}


Thanks in advance
http://www.cplusplus.com/reference/iostream/manipulators/

You're looking specifically for setw and the adjustment format flags.
Topic archived. No new replies allowed.