1. #1

    C++ Homework Help

    So I have a basic assignment...

    Code:
    // File:     program2.cpp
    // Author:   Name
    // Course:   CSC 135
    // Date:     September 25, 2013
    // Purpose:  The program will ask for the number of acres and actual property value per acre. It will calculate total actual value, assessment value and the property tax.
    
    #include <iostream>
    #include <iomanip>
    #include <cmath>
    using namespace std;
    
    const double TAXRATE = .064;
    
    int main()
    {
      int acresOwned;
      double valuePerAcre, totalValue, assmntValue, propTax;
    
      // Inputs
      cout << "Enter the number of acres owned: ";
      cin >> acresOwned;
      cout << "Enter the actual value per acre: ";
      cin >> valuePerAcre;
    
      // Calculations
      totalValue = valuePerAcre * acresOwned;
      assmntValue = totalValue * .60;
      propTax = assmntValue / 100 * TAXRATE;
    
      // Outputs
      cout << endl;
      cout << setw(8) << fixed << setprecision(2) << endl;
      cout << "Acres owned: " << acresOwned << endl;
      cout << "Total actual value: $ " << totalValue << endl;
      cout << "Assessment value:  $ " << assmntValue << endl;
      cout << "Property tax: $ " << propTax << endl;
    
      return 0;
    }
    I'm curious if anyone knows how I can line up the outputs to their decimals? the current setw and setprecision arn't doing anything.

  2. #2
    //edit derp, I didn't read your question correctly.

    To line things up by the decimal you're going to have to play around with whitespace. If you can guarantee every number will have the same precision, it's not bad.

  3. #3
    Some manipulators are sticky, but most aren't. You generally want to use them right before you output the value you want to manipulate.

    This may be what you're looking for:
    Code:
      cout << endl;
      cout << fixed << setprecision(2) << endl;
      cout << setw(25) << right << "Acres owned:   "        << setw(8) << acresOwned << endl;
      cout << setw(25) << right << "Total actual value: $ " << setw(8) << totalValue << endl;
      cout << setw(25) << right << "Assessment value: $ "   << setw(8) << assmntValue << endl;
      cout << setw(25) << right << "Property tax: $ "       << setw(8) << propTax << endl;
    Last edited by Bleah; 2013-09-25 at 03:43 AM.

  4. #4
    Quote Originally Posted by Bleah View Post
    Some manipulators are sticky, but most aren't. You generally want to use them right before you output the value you want to manipulate.

    This may be what you're looking for:
    Code:
      cout << endl;
      cout << fixed << setprecision(2) << endl;
      cout << setw(25) << right << "Acres owned:   "        << setw(8) << acresOwned << endl;
      cout << setw(25) << right << "Total actual value: $ " << setw(8) << totalValue << endl;
      cout << setw(25) << right << "Assessment value: $ "   << setw(8) << assmntValue << endl;
      cout << setw(25) << right << "Property tax: $ "       << setw(8) << propTax << endl;
    I actually figured it out and got it to work, looks very similar to this, so I just cleaned it up with how yours looks!

    Thanks a lot for the help guys

Posting Permissions

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