0

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

Edited by soapyillusion: n/a

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
0
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';
    }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.