Thread: formatting output

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    12

    formatting output

    <edit>
    i gave old code by accident. here is the actual code
    </edit>

    here is the code i am concerned with. the formatted output looks like it is correct after you run the program, but i don't know if this is how it should be done. i was getting a few warning messages so i thought i would ask the experts. i also attached a zip file with the entire program and input/output files.

    Code:
    //Print heading to log file program5.out
    fout<<STARS<<endl;
    fout<<setw(40-storeName.length())<<storeName<<endl;
    fout<<STARS<<endl;
    fout<<"Product Code   Description                    Unit Price"<<endl;
    fout<<"************   *************************      **********"<<endl;
    fout<<setiosflags(ios::fixed|ios::showpoint)<<setprecision(2);
    
    
    //Format file output with setw and length
    fout<<setw(5)<<productCode<<setw(14-productCode.length()+descriptions[index].length())<<descriptions[index]<<setw(42-descriptions[index].length())<<price[index]<<endl;
    }
    
    else
    {
       cout<<"***ERROR: PRODUCT CODE "<<productCode<<" is not in list."<<endl;
       fout<<setw(5)<<productCode<<"          Invalid Product Code"<<endl;
    }
    i put the heading code there so you could get an idea of what i am trying to get the output to look like. if you don't understand you could just run the program i attached and see what i am trying to do. like i said...the way i did it looks right, but i'm not sure if it is because of warning messages. any help is greatly appreciated.
    Last edited by z.tron; 11-22-2002 at 01:33 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Switch statement and returning the correct output
    By slowcoder in forum C Programming
    Replies: 6
    Last Post: 09-28-2006, 04:00 PM
  2. Formatting output to screen from a file
    By clearrtc in forum C Programming
    Replies: 2
    Last Post: 08-20-2006, 03:19 PM
  3. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 01:11 AM
  4. dos game help
    By kwm32 in forum Game Programming
    Replies: 7
    Last Post: 03-28-2004, 06:28 PM
  5. formatting output
    By spliff in forum C Programming
    Replies: 2
    Last Post: 08-14-2001, 06:50 PM