CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2009
    Posts
    38

    outFILE setprecision and right wont work

    Hi guys, I can't seem to use setprecision, right, setw, or fixed on my outFILE lines. nothing happens. I need to get all the decimals to line up and the numbers are on the right side.

    this is my code so far

    #include <iostream>
    #include <fstream>
    #include <iomanip>
    using namespace std;

    int main ()

    {
    ofstream outputFile;
    double sales , total , year , statetax, countytax;
    char month[10];

    outputFile.open("sales.txt");

    cout << "Please enter the month for this report:";
    cin >> month;
    cout << "Please enter the year for this report:";
    cin >> year;
    cout << "Please enter the total income for this month:";
    cin >> total;
    sales = total / 1.06;
    cout << "Sales Tax Report saved to file: SalesTaxData.txt" << endl;

    outputFile << "Month: " << month << endl;
    outputFile << "-------------" << endl;
    outputFile << "Total Collected: " << total << endl;
    outputFile << "Sales : " << sales << endl;
    countytax = sales * .02;
    statetax = sales * .04;
    outputFile << "County Sales Tax: $" << countytax << endl;
    outputFile << "State Sales Tax: $" << statetax << endl;
    outputFile << "Total Sales Tax: $" << countytax + statetax << endl;
    cout << setprecision(2) << right << fixed << endl;
    outputFile.close();

    return 0;

    }

  2. #2
    Join Date
    Mar 2010
    Posts
    11

    Re: outFILE setprecision and right wont work

    You should use these manipulators before you reference the variables. For example,

    double x = 1.23456
    cout << setprecision (5) << x << endl;

  3. #3
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401

    Re: outFILE setprecision and right wont work

    Quote Originally Posted by Sabensohn70 View Post
    Hi guys, I can't seem to use setprecision, right, setw
    I don't see you using setw.
    More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf

    Premature optimization is the root of all evil --Donald E. Knuth


    Please read Information on posting before posting, especially the info on using [code] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured