Function error

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
void orderItem( Inventory *& inven , OrderList *& order , int &index ){
    
    displayItem(inven,index);
    
    string status = "";
    string name = "";
    string item = "";
    double price = 0.00;
    int quan = 0;
    int orderIndex = 0;
    char choice = 'a';
    ifstream inFile;
    
    //readOrder( order ,inFile , orderIndex );
    
    do{
        cout << "Do you want add an order [y / n] : ";
        cin  >> choice;
        switch( choice ){
            case 'y':
            case 'Y':
                cin.ignore();
                cout << "Enter company name : ";
                getline( cin , name );
                order[orderIndex].setCompanyName( name );

                cout << "Enter item name : ";
                getline( cin , item );
                order[orderIndex].setItemName( item );

                cout << "Enter quantity : ";
                cin  >> quan;
                order[orderIndex].setQuantity( quan );

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

                status = "pending";
                order[orderIndex].setOrderStatus(status);
                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');
}


main.cpp
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
/* 
 * File:   main.cpp
 * Author: Lim
 *
 * Created on April 2, 2013, 12:48 PM
 */

#include <cstdlib>
#include "Inventory.h"
#include "OrderList.h"

int main(int argc, char** argv) {

    ifstream inFile;
    Inventory *inven;
    OrderList *order;
    int index = 0;
    readInven(inven,inFile,index);
    inven = new Inventory[index];
    
    recordStore(inven,index);
    orderItem(inven,order,index);
    return 0;
}


why i cannot set the order status.
if i set it my program will pop out an error.
if i comment it out my program able to run . why ?


and at line 25
i able to run it in netbean

but why i cannot run in visual studio?
will pop out an error message. can any expert help pls..
Last edited on
If i assign the order into

1
2
OrderList *order;
order = new OrderList;

and it's work

but now my problem is. my order might have an array because i read from file

but if i define like
1
2
OrderList *order;
order = new OrderList[orderIndex];

and my program will crash. can somebody tell me why pls
problem solved by created
 
orderIndex += 1


will ask if any problem exist again . thanks
Topic archived. No new replies allowed.