Hey guys I have a almost seemingly trivial problem yet its probally so simple. No matter how hard i try I can never seem to get the format of the cout statements to look they way i want. I always use the setw command and set precsion, even the left and right commands. However in this particular program I cant get the output to look the way i want.

What would be the correct code to make this output appear (using iomanip commands)

Fried Chicken 12.99
Pork Chops 10.99
Soda 2.99
Tax .50
total 26.77

Ive done all the other work so I just need to know the correct order of the setw and set precsion codes.

*With all the decimal place lined up!
-Thanks

struct item
{
    string name;
    float price;
};


int main()
{
    item it[] = {
        {"Fried Chicken",12.99F},
        {"Pork Chops", 10.99F},
        {"Soda", 2.99F}
    };
    for(int i = 0; i < sizeof(it)/sizeof(it[0]); i++)
    {
        cout << setw(20) << left << it[i].name 
            << setw(5) << right << it[i].price << '\n';
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.