Loop array and sum error (Homework Help)

this is part of a cash register program. I want to receive client order by input item_to_buy, and calculate the sum by total_price. However, when I use for loop to calculate the sum as follow, it print out -858993454 sth like that when I run the code. Could someone give advice please?




int item_to_buy, total_price;
int price[11] ={0,4, 6, 8, 9, 1, 3, 4, 6, 3, 5};

for (item_to_buy=0, total_price=0; item_to_buy >=0; total_price+=price[item_to_buy])

cin>>item_to_buy;

cout<<"Total: "<<total_price;
Topic archived. No new replies allowed.