Setting Right Alignment

D

deanfamily11

Ok, here's another problem I'm having. I've tried several different things,
but I just can't get anything to be right justified. Any thoughts?


#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{

//declare file stream variables
ofstream outData;

//declare variables
double value, taxAmt, propTax;
double tax = 0.92, rate = 1.05;
outData.setf(ios::right);
outData.setf(ios::left);

//open the output file
outData.open("c:\\review\\chapter 2\\exercise 4\\houseData.txt");

//get the assessed value
cout << "Enter the Assessed Value of the property: ";
cin >> value;
cout << endl;

//calculate values
taxAmt = value * tax;
propTax = (taxAmt / 100) * rate;

//begin outputting data
outData << "Assessed Value:";
outData << right;
outData << value << endl;
outData << left;
outData << "Taxable Amount:";
outData << right;
outData << taxAmt << endl;
outData << left;
outData <<"Tax Rate for each $100:";
outData << right;
outData << rate << endl;
outData << left;
outData <<"Property Tax:";
outData << right;
outData << propTax << endl;

//end the program
cout << "File created. Ending the program." << endl;

return 0;

}
 
D

deanfamily11

That's not working either, or I'm not using them right. Here is how I am
using them now:
I have also used them where the outData << left and outData << right are.

#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{

//declare file stream variables
ofstream outData;

//declare variables
double value, taxAmt, propTax;
double tax = 0.92, rate = 1.05;
setiosflags(ios_base::right);
resetiosflags( ios_base::left );

//open the output file
outData.open("m:\\review\\chapter 3\\exercise 4\\houseData.txt");

//get the assessed value
cout << "Enter the Assessed Value of the property: ";
cin >> value;
cout << endl;

//calculate values
taxAmt = value * tax;
propTax = (taxAmt / 100) * rate;

//begin outputting data
outData << "Assessed Value:";
outData << right;
outData << value << endl;
outData << left;
outData << "Taxable Amount:";
outData << right;
outData << taxAmt << endl;
outData << left;
outData <<"Tax Rate for each $100:";
outData << right;
outData << rate << endl;
outData << left;
outData <<"Property Tax:";
outData << right;
outData << propTax << endl;

//end the program
cout << "File created. Ending the program." << endl;

return 0;

}
 
M

Moonlit

Hi,

You are using them wrong.

Here is how it works

The iomanipulators are classes. Now somewhere there is a definition like
this

streamclass( const iomanip& manip )
{
// use flag in manip to manipulate myself

}

So what you have to do is
OutDate << setiosflags( ios_base::left ) << resetiosflags( ios_base::right)
<< poprTax << ...



--


Regards, Ron AF Greve

http://moonlit.xs4all.nl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top