Thread: Alignment Issues.....

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    1

    Alignment Issues.....

    I wish to make a program that gives computations for a water bill for various respective companies.

    The programs runs fine, I just want to format it to where my outputs are right justified to make it look nicer.

    code:
    Code:
    #include <iostream>#include <iomanip>
    #include <string>
    
    
    using namespace std;
    
    
        int main()
    {
        char name [256];
        char type;
        double gallons;
        double base;
        double fee;
        
        cout << "Please Name/Title: " << endl;
            cin.getline(name, 256);
    
    
        cout << "Please insert customer type: \n (R= Resident) \n (B= Business) \n (G= Govt.) \n (N= NonProfit): " << endl;
            cin >> type;
        
        cout << "Please enter number of gallons used: " << endl;
            cin >> gallons;
    
    
        cout << fixed << right << setprecision(2) << showpoint;
        cin.setf(ios::right);
    
    
        cout << name << endl;
    
    
        cout << "Gallons Used: " << setw(10) << setfill('.') << "  " << right << gallons << endl;
    
    
        switch (type)
        {
      case 'R':
        base = 15.00;
            if (gallons > 1000)
            {
                    fee = (gallons - 1000) * .02;
            }
        break;
      case 'B':
        base = 25.00;
            if (gallons > 2000)
            {
                    fee = (gallons - 2000) * .03;
            }
        break;
      case 'G':
        base = 5.00;
            if (gallons > 500)
            {
                    fee = (gallons - 500 ) * .01;
            }
        break;
    
    
        case 'N':
        base = 5.00;
            if (gallons > 500)
            {
                    fee = (gallons - 500 ) * .01;
            }
        break;
    
    
        case 'r':
        base = 15.00;
            if (gallons > 1000)
            {
                    fee = (gallons - 1000) * .02;
            }
        break;
        case 'b':
        base = 25.00;
            if (gallons > 2000)
            {
                    fee = (gallons - 2000) * .03;
            }
        break;
        case 'g':
        base = 5.00;
            if (gallons > 500)
            {
                    fee = (gallons - 500 ) * .01;
            }
        break;
    
    
        case 'n':
        base = 5.00;
            if (gallons > 500)
            {
                    fee = (gallons - 500 ) * .01;
            }
        break;
    }
    
    
        cout << "Water base fee: "  << setfill('.')  << setw(8)  << "$ " << right << base << endl;
    
    
        cout << "Water usage fee: " << setfill('.') << setw(7)  << "$ "  << right << fee <<endl;
    
    
        cout << "Sewage base fee: " << setfill('.') << setw(7)  << "$ "  << right << base << endl;
    
    
        cout << "Sewage usage fee: " << setfill('.') << setw(6) << "$ "  << right << fee * .8 << endl;
    
    
        cout << "Total due: " << setfill('.') << setw(13)  << "$ " << right << (base * 2) + fee + (fee * .8) << endl;
        
        cin.get();
        cin.get();
        
    return 0;
    }
    i would like the output to show as so:

    Gallons used ................ 100000
    Water base fee ..............$ 5.00
    Water usage fee .........$ 995.00
    Sewage base fee ............$ 5.00
    Sewage usage fee .......$ 796.00
    Total due .................$ 1801.00

    (aligned, of course)

    any help would be appreciated
    -Apo-S

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Read through How to format output C++ - FAQ. Looks like you know of the iomanip library, just maybe not all the members? Additionally, unless required by your assignment, you should be using std::string instead of C style char arrays. Also, you should indent your code properly.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GCC & Alignment
    By GReaper in forum Tech Board
    Replies: 2
    Last Post: 02-09-2011, 04:51 AM
  2. Data Alignment Issues...
    By aaba1 in forum C Programming
    Replies: 1
    Last Post: 10-03-2010, 11:03 AM
  3. gcnew : alignment issues?
    By mynickmynick in forum C++ Programming
    Replies: 1
    Last Post: 08-27-2008, 02:42 AM
  4. Alignment
    By wiz23 in forum C++ Programming
    Replies: 9
    Last Post: 05-03-2005, 07:33 AM
  5. help with alignment
    By bigb1999 in forum C++ Programming
    Replies: 1
    Last Post: 02-04-2002, 06:22 PM