Thread: stupid formatting ?

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    5

    stupid formatting ?

    Pardon the mess. Program works, 1 annoying thing is the divider1, always runs into the Attendance Report. All the other dividers behave normally. I tried just using a cout for the "Attendance Report", then moved it to a void/void, and that one divider does the same thing in each case. Thanks for any help, I'm sure it's something very simple....

    Code:
    #include <iostream>
    #include <iomanip>
    //#include <string>
    
    using namespace std;
    
    //constants and  voids
    const int SCREEN_WIDTH = 70;
    const char BLANK = ' ';
    void PrintWelcome (void);
    void PrintWelcome2 (void);
    void Divider1 (void);
    void Divider2 (void);
    
    
    int main (void)
    {
    	int NumberOfVisitors;
    	int  CMorn;
    		int CAft;
    		int CTot;
    		int CPer;
    		int FMorn;
    		int FAft;
    		int FTot;
    		int FPer;
    		int RMorn;
    		int RAft;
    		int RTot;
    		int RPer;
    		int TotalMorn;
    			int TotalAft;
    			int GrandTot;
    			int TotalMorning;
    			int TotalAfternoon;
    			int GrandTotal;
    
    
    
    PrintWelcome ();
    //cout << setw(52) << "Aaron's Amusement Park" << endl;
    //cout << endl;
    
    Divider1 () ;
    cout << endl;
    
    
    //cout << setw(52) << "Attendance Report" << endl;
    PrintWelcome2 ();
    cout << endl;
    
    Divider1 () ;
    cout << endl;
    cout << "Enter the number  of visitors at the park : ";
    
    cin  >> NumberOfVisitors ;
    if ( NumberOfVisitors > 0)
    
    cout << "good"  << endl;
    
    else cout << "error";
    Divider2 ();
    
    cout << "For Ride #1, The Carousel:"  ;
    cout << endl;
    cout << "Morning Riders: " ;
    cin >> CMorn;
    cout << endl;
    cout << "Afternoon Riders"  ;
    cin >> CAft;
    cout << endl;
    CTot = CAft + CMorn;
    cout << "Total Riders: " << CTot  ;
    CPer = (CTot / double(NumberOfVisitors)) * 100;
    cout << "Percent of Riders: " << CPer ;
    cout << endl;
    Divider2 ();
    
    cout << "For Ride #2, The Ferris Wheel:" ;
    cout << "Morning Riders: "  ;
    cin >> FMorn;
    cout << endl;
    cout << "Afternoon Riders" << endl;
    cin >> FAft;
    cout << endl;
    FTot = FAft + FMorn;
    cout << "Total Riders: " << FTot  ;
    FPer = (FTot / double(NumberOfVisitors)) * 100;
    cout << endl;
    cout << "Percent of Riders: " << FPer ;
    cout << endl;
    Divider2 ();
    
    cout << "For Ride #3, The Roller Coaster:" ;
    cout << "Morning Riders: " << endl;
    cin >> RMorn;
    cout << "Afternoon Riders" << endl;
    cin >> RAft;
    RTot = RAft + RMorn;
    cout << "Total Riders: " << RTot  ;
    RPer = (RTot / double(NumberOfVisitors)) * 100;
    cout << "Percent of Riders: " << RPer ;
    TotalMorning = CMorn + FMorn + RMorn;
    TotalAfternoon = CAft + CMorn +  RMorn;
    GrandTotal = TotalMorning + TotalAfternoon;
    cout << "Total Morning Riders: " << TotalMorning ;
    cout << "Total Afternoon Riders: " << TotalAfternoon ;
    cout << "Grand Total Riders: "  << GrandTotal;
    cout << endl;
    
    
    Divider2 ();
    
    
    	return 0;
    }
    void PrintWelcome (void)
    {
    	cout << setw(52) << "Aaron's Amusement Park";
    	cout << endl ;
    
    } 
    void PrintWelcome2 (void)
    {
    	cout << setw(52) << "Attendance Report";
    	cout << endl;
    }
    void Divider1 (void)
    {
    	cout << setfill ('=');
    	cout << setw(SCREEN_WIDTH) << BLANK << endl;
    }
    void Divider2 (void)
    {
    	cout << setfill ('-');
    	cout << setw(SCREEN_WIDTH) << BLANK << endl;
    }

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Reset the fill to blank after setting it to something else.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    5
    added a cout.fill(' '); right after attendance and that worked...not sure why none of the others behaved this way tho...

    Thanks!!

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    I guess you want your output like so:
    Code:
                                   Aaron's Amusement Park
     =====================================================================
     
                                        Attendance Report
     
     =====================================================================
     
     (ignore the breaks in the lines containing the = signs,  
     they're only showing because this forum software forces breaks after X number of characters)
    I put "cout << setfill(' ');" as the last line of Divider1(), I'd recommend doing the same to Divider2(). Reseting the fill right after changing it would be a better practice than going across two different functions.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stupid, stupid question
    By xelitex in forum C++ Programming
    Replies: 5
    Last Post: 12-22-2004, 08:22 PM
  2. dos game help
    By kwm32 in forum Game Programming
    Replies: 7
    Last Post: 03-28-2004, 06:28 PM
  3. Incredibly Stupid People
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 09-09-2003, 04:12 PM
  4. Your Best thread and your most stupid thread ??
    By jawwadalam in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 01-03-2003, 07:41 PM
  5. Stupid people should wear SIGNS
    By C_Coder in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 07-15-2002, 08:49 AM