why my inFile will insert extra 1 number after second loop

1
2
3
4
5
6
7
8
9
10
11
12
13
1
KEZN
2HITACHI
HTC2011-500TB
2
1000
4
SAMSUNG
ST-56/2-PLASMA
3
13500
6
PENDING


my txt . the 3rd line should be Hitachi only. why it will hv extra 2 over there?
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
void orderItem( Inventory *& inven , OrderList *& order , int &index , int &orderIndex , int &itemIndex ){
    
    displayItem(inven,index);

    bool matchItem = false;
    bool again = false;
    
    string status = "";
    string name = "";
    string item = "";
    string model = "";
    double price = 0.00;
    double warranty = 0.00;
    int quan = 0;
    
    char choice = 'a';
    char continueBuy ='a';
    ifstream inFile;
    ofstream outFile;
    
     cout << "Enter company name : ";
     getline( cin , name );
     stringtoUpper( name );
     order[orderIndex].setCompanyName( name );
     do{
        cout << "Do you want add an order [y / n] : ";
        cin  >> choice;
        switch( choice ){
            case 'y':
            case 'Y':
                do{
                    cin.ignore();
                    do{
                         cout << "Enter item name : ";
                         getline( cin , item );
                         stringtoUpper(item);

                         for( int i = 0 ; i < index ; i++ ){
                             if( item != inven[i].getItemName() )
                                 matchItem = false;
                             else{
                                 matchItem = true;
                                 break;
                             }
                         }
                         if( !matchItem )
                             cout << "Item Does not exist!" << endl;
                     }while(!matchItem);
                     order[orderIndex].orderItem[itemIndex].itemName = item;

                     cout << "Enter quantity : ";
                     cin  >> quan;
                     while( cin.fail() ){
                         cin.clear();
                         cin.ignore(100,'\n');
                         cout << "You cannot enter character , only number" << endl;
                         cout << "Enter quantity : ";
                         cin  >> quan;
                     }
                     order[orderIndex].orderItem[itemIndex].quantity = quan;

                     for( int i = 0 ; i < index ; i++ ){
                         if( item == inven[i].getItemName() ){
                             price = quan * inven[i].getPrice();
                             model = inven[i].getModel();
                             warranty = inven[i].getWarranty();
                         }
                     }
                     cout << "Total Price : RM" << price << endl;
                     order[orderIndex].orderItem[itemIndex].price = price;
                     order[orderIndex].orderItem[itemIndex].modelName = model;
                     order[orderIndex].orderItem[itemIndex].warranty = warranty;

                     status = "pending";
                     stringtoUpper(status);
                     order[orderIndex].setOrderStatus(status);

                     
                     itemIndex++;//to increase 1 array, if not array will not be save and output error
                     cout << "Do you still want to continue [y/n] ? : ";
                     cin  >> continueBuy;
                     do{
                         switch( continueBuy ){
                             case 'y':
                             case 'Y':
                                 again = true;
                                 break;
                             case 'n':
                             case 'N':
                                 again = false;
								 orderIndex++;
                                 saveOrder(order,outFile,orderIndex,itemIndex);
                                 break;
                             default:
                                 cout << "Invalid input !" << endl;
                                 break;
                         } 
                     }while( choice != 'Y'&&choice != 'y'&&choice != 'n'&& choice!='N' );       
                }while(again == true);
                break;
            case 'N':
            case'n':
                cout << "You cancel order item" << endl;
                break;
            default:
                cout << "Invalid input ! Please re-enter" << endl;
                break;
        }
    }while( choice != 'Y' && choice != 'y' && choice != 'N' && choice !='n');
}
Last edited on
editted
Last edited on
Topic archived. No new replies allowed.