How to display the balance and checkout so that the user will know how much the balance left from his or her budgetwhile buying | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to display the balance and checkout so that the user will know how much the balance left from his or her budgetwhile buying

then each time the user pick any item & quantity the remaining balance and total balance Total pt should also be displayed when the user is done in buying https://code.sololearn.com/cKz2vXPPo64m/?ref=app Thank you in advance 😊

13th Dec 2021, 8:29 AM
shlee_
shlee_ - avatar
37 Answers
+ 4
I have an idea, I'll give you an overview of it, but you should try to implement it. Add the quantity ordered inside the class Item, when nothing is ordered, it should be 0. You can use an std::vector like a shopping cart, to add and delete items when you need. For more details about how to use std:: vector, refer here:https://www.learncpp.com/cpp-tutorial/an-introduction-to-stdvector/ If you already have the item in the cart, you can just increase its quantity. Else, you can add a new item. You'll figure it out when you start working with vector.
13th Dec 2021, 8:40 AM
Rishi
Rishi - avatar
+ 4
All right, let me think ... 🤔
14th Dec 2021, 9:34 AM
Agnes Ahlberg
Agnes Ahlberg - avatar
+ 3
Agnes Ahlberg yeah there are 10 items for each category total of 100
14th Dec 2021, 9:28 AM
shlee_
shlee_ - avatar
+ 3
Agnes Ahlberg But just me an example for one category only or just do a code for 1 category only so I can see on how to make a class for it
14th Dec 2021, 9:29 AM
shlee_
shlee_ - avatar
+ 3
Nope, just a basic array
14th Dec 2021, 9:32 AM
shlee_
shlee_ - avatar
+ 3
Ok,😌
14th Dec 2021, 9:40 AM
shlee_
shlee_ - avatar
+ 3
Okay 😌
14th Dec 2021, 9:42 AM
shlee_
shlee_ - avatar
+ 3
Here is an idea. Look carefully at the functions cancel_menu, sub_menu, and menu, to get an idea of how the processing works without nesting switches and the calls to add and remove orders. It is not yet complete, though, but maybe you already get the idea and can complete it. https://code.sololearn.com/cGqXE6Tz11f9
14th Dec 2021, 11:10 AM
Agnes Ahlberg
Agnes Ahlberg - avatar
+ 3
Agnes Ahlberg thanks for your help I try to understand it too😊😊
14th Dec 2021, 11:31 AM
shlee_
shlee_ - avatar
+ 3
Agnes Ahlberg see my comment in your code
14th Dec 2021, 12:02 PM
shlee_
shlee_ - avatar
+ 3
Agnes Ahlberg I see it
14th Dec 2021, 1:59 PM
shlee_
shlee_ - avatar
+ 2
shlee_ why do you use the bollean value true to indicate an item is ordered? Why not use integers to count how many the user ordered? Like: Say the customer ordered 5 Orange Juice Item Juice("Orange Juice",5,15,15); If the user didn't order any milk, then, Item Milk("Milk",0,18.5);
13th Dec 2021, 9:38 AM
Rishi
Rishi - avatar
+ 2
Rishi I have one day left only 😔 to submit my work... I having a lot of assignments last week can you give me at least an example I don't understand vectors
13th Dec 2021, 10:26 AM
shlee_
shlee_ - avatar
+ 2
shlee_ Take a look at this simple, short and clear explanation of vector and it's implementation in this lesson by Hatsy Rei https://www.sololearn.com/learn/261/?ref=app
13th Dec 2021, 12:07 PM
Rishi
Rishi - avatar
+ 2
I have only quickly glanced at it. As I understand it, you need to maintain a sort of shopping cart to which you can add and remove items from? And you have not learned about vectors or any sort of collection class? You can make a shopping cart class and maintain number of ordered items in there. Without vectors and maps you can use a variable for each item type. This is not optimal for a variety of reasons, but it will work for now. Just increase by the number of ordered item, and decrease if order is canceled. At the end, each item type carries its price, and the cart all information about the quantities, allowing you to calculate the total cost.
13th Dec 2021, 2:40 PM
Agnes Ahlberg
Agnes Ahlberg - avatar
+ 2
Rishi Agnes Ahlberg I already know how to make more categories but still don't how how to mange the add and delete item for the cart please I really need help https://code.sololearn.com/cwFEt8D3yM94/?ref=app
14th Dec 2021, 8:29 AM
shlee_
shlee_ - avatar
+ 2
This is a very different design now 🤔 You will need a way to display the items in the shopping cart and options to remove them. Is that supposed to be done from the main menu?
14th Dec 2021, 9:08 AM
Agnes Ahlberg
Agnes Ahlberg - avatar
+ 2
Yeah, it is supposed to be done on main menu I think in which the user can add or delete an item they want to purchase but I don't know how to do that thing Agnes Ahlberg each category has 10 items in each and the user has a given money of 500000 as a grocery gift and the balance must also shown as they buy an item
14th Dec 2021, 9:10 AM
shlee_
shlee_ - avatar
+ 2
Okay. Now your first design used objects. Do you want to (or have to?) use objects?
14th Dec 2021, 9:13 AM
Agnes Ahlberg
Agnes Ahlberg - avatar
+ 2
Agnes Ahlberg I'm focusing on calculations part depends on how what the simplest way to get it it's just that I don't know how to make categories on it so I change my design ...
14th Dec 2021, 9:16 AM
shlee_
shlee_ - avatar