Urgent!! Shopping program

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
void customerDetails::viewCart()
{
    for (int i=0; i<itemDetailsCount; i++)
    {
        cout<<"\nName - "<<customerDetailsObject[0].itemDetailsObject[i].name<<endl;

        cout<<"Rs - "<<customerDetailsObject[0].itemDetailsObject[i].cost<<endl;

        cout<<"Sku No - "<<customerDetailsObject[0].itemDetailsObject[i].sku<<endl;
    }

    cout<<"\nTotal Cost "<<itemDetailsObject[0].cost+itemDetailsObject[1].cost+itemDetailsObject[2].cost<<endl;

    int selection;

    cout<<"\n1.Checkout"<<endl;
    cout<<"\n2.Back"<<endl;

    cin>>selection;
    switch (selection) 

    {
        case 1:
            categoryDetailsObject.chooseCategory();
            break;
        case 2:
            categoryDetailsObject.displayMusicItemDetails();
            break;
        default:viewCart();
            break;
    }  
}




this is part of a shopping program which i have written i wanted to calculate the total cost in view cart part so i couldnt figure out how to add the total cost ,there can be any number of items which could be added in add to cart menu btw itemDetailsObject[50] the code which i have blocked is one way but if there are 50 items to be added that method wont be ideal
1
2
3
4
5
6
    int total_cost = 0;
    for (int cost_idx = 0; cost_idx < itemDetailsCount; cost_idx++)
    {
        total_cost += itemDetailsObject[cost_idx].cost;
    }
    cout<<"\nTotal Cost "<<total_cost<<endl;

Urgent!! Shopping program

Let me guess... Big shoe sale??? Sorry, but that made me LOL!

Also here: http://cplusplus.com/forum/general/43552/
Last edited on
hehehe i am studying C++ so that it would help me in learning objective C so i am working on big C++ large programs :) , its in general forum as well cause sometimes ppl miss in beginner section so to be safe i put it over there
Topic archived. No new replies allowed.