0

I don't know how to call my array element. I want the array element in orange circle to be in place where the arrow pointing.

https://code.sololearn.com/c45IwB03ko22/?ref=app

9th Dec 2020, 3:01 AM
Airone Kheji R. Alix
Airone Kheji R. Alix - avatar
9 Réponses
+ 1
From your description I seem to get an impression that only 1 unit is allowed to be purchased per product, is it possible for a customer to buy many units of a product? If a customer can purchase many unit per product then you need to make the code multiply unit price and quantity (per product) also. Following up on your example Product Price Qty Subtotal Item [0]: 1 1 1 Item [2]: 1 1 1 Item [3]: 1 1 1 Item [12]: 8 1 8 Item [14]: 13 1 13 Grand total ________ 24 The Sub and Grand total varies by quantity of a product purchased.
9th Dec 2020, 8:18 AM
Ipang
+ 2
What exactly is the program supposed to do? Describe what it should do, what did it do wrong, what input needed and the respective output. The image was obscured by the handwritten arrows, not sure I understand what the arrow was trying to point out. Maybe you be better of just describe it. Never mind if you have solved it ..
9th Dec 2020, 4:19 AM
Ipang
+ 2
In line 34, buy should be an array, and the line should be:     cin >> buy[x]; Adjust the definition of buy to be int buy[5]. Line 38 should change from: cout <<"Item [" << price[x] << "]: " << buy << endl; To: cout <<"Item [" << buy[x] << "]: " << price[buy[x]] << endl; Line 39 should not modify the price list. Instead it should total the amounts from price. Outside the loop define a float variable named total and initialize it to zero. Then change current line 39 from this:         price[x] += buy; To:         total += price[buy[x]]; And then line 41 will need to change from:     currentAllowance = allowance - buy; To:     currentAllowance = allowance - total; These changes should get your code in better working order. Keep trying!
9th Dec 2020, 7:22 AM
Brian
Brian - avatar
+ 1
Output should be, you will pick 5 items from items 0 to 14, then the item no. You choose will be shown inside this "[ ]". Then the array price should be shown beside it. For example is: You choose item 0,2,3,12, and14. The output should be like this: Item [0]: 1 Item [2]: 1 Item [3]: 1 Item [12]: 8 Item [14]: 13
9th Dec 2020, 5:06 AM
Airone Kheji R. Alix
Airone Kheji R. Alix - avatar
+ 1
Then add the prices and subtract to the allowance 100.
9th Dec 2020, 5:07 AM
Airone Kheji R. Alix
Airone Kheji R. Alix - avatar
+ 1
I hope you can help me in my program, your free to ask if there's anything you don't understand.
9th Dec 2020, 5:10 AM
Airone Kheji R. Alix
Airone Kheji R. Alix - avatar
+ 1
Its okay but its too complicated for me to make that kind of program.
9th Dec 2020, 8:24 AM
Airone Kheji R. Alix
Airone Kheji R. Alix - avatar
+ 1
Don't worry, I was just asking for confirmation, it was not an answer so you don't have to mark my confirmation. If you only allow customer to buy 1 unit per product, then you can see Brian's suggestion earlier, and try to implement it in code. Feel free to ask for any further doubt 👌
9th Dec 2020, 8:30 AM
Ipang
9th Dec 2020, 3:05 AM
Airone Kheji R. Alix
Airone Kheji R. Alix - avatar