Not sure to use setw or what (interface)

This is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;

class Food{
 public:
    vector <int> pizzaID;
    vector <int> pastaID;
    vector <int> drinksID;
    vector <string> pizzaName;
    vector <string> pastaName;
    vector <string> drinksName;
    vector <double> pizzaPrice;
    vector <double> pastaPrice;
    vector <double> drinksPrice;
    Food() :
        pizzaID(), pastaID(), drinksID(),
        pizzaName(), pastaName(), drinksName() {}

    void defaultFood(){
        pizzaID.push_back(1);
        pizzaID.push_back(2);
        pizzaID.push_back(3);
        pizzaID.push_back(4);
        pizzaID.push_back(5);
        pizzaName.push_back("Beef Pepperoni");
        pizzaName.push_back("Chicken Pepperoni");
        pizzaName.push_back("Cheese Pepperoni");
        pizzaName.push_back("Island Supreme");
        pizzaName.push_back("Seafood Supreme");
    }

    void displayPizza(){
        for(int n=0; n<pizzaID.size(); n++){
            cout<<setw(2)<<pizzaID[n]<<"     "<<pizzaName[n];
            cout<<setw(20)<<"RM"<<endl;
        }
    }
};

int main(){
    Food f;
    f.defaultFood();
    f.displayPizza();
}


This is the output for the code:
1
2
3
4
5
1     Beef Pepperoni                    RM25.00
2     Chicken Pepperoni                    RM25.00
3     Cheese Pepperoni                    RM20.00
4     Island Supreme                    RM22.00
5     Seafood Supreme                    RM25.00


This is the output that I want:
1
2
3
4
5
1     Beef Pepperoni                    RM25.00
2     Chicken Pepperoni                 RM25.00
3     Cheese Pepperoni                  RM20.00
4     Island Supreme                    RM22.00
5     Seafood Supreme                   RM25.00


I'm not sure what to use in order to get what I want. Need suggestion. Thanks!
 
cout << left << setw(2) << pizzaID[n] <<"     "<< setw(20) << pizzaName[n] <<"RM "<<endl;


setw() sets the maximum width to be taken by the next value inserted, by default it is aligned to the right, so which left formatter comes handy
Last edited on
Topic archived. No new replies allowed.