My First Project

Hello everyone :D

I recently made my first C++ project (console app), and I want any feedback you guys want to give me when it comes to the code I produced :D

Here's the video:
https://www.youtube.com/watch?v=R8NbviOnfF8

Here's the source code:
https://github.com/KreezyStudios/Vending-Machine-CPP

If there are any practices I should try out to improve my code or something I do that I should avoid please let me know :)

Thanks!
closed account (E0p9LyTq)
A quick read suggestion, just off the top of my head:

Avoid #define if you can, use const or constexpr variables instead.
Thanks, I just looked up the difference and realized what I was doing wasnt the best way of going about it
Class Item is way too complex. Why does each item need it's own map? From what I can tell, the map will only contain one item. Class ItemData contains all that you need for class Item.

VendingMachine::_items should be a vector, not a map.

Hello kreezy,

Like FurryGuy I took a quick look at your project. I noticed that "#include" files like "iostream" and "string" should be in the ".cpp" files not header files. Over time I created "stdhead.hpp" and put header files like "iostream", "iomanip", "string", "vector" and a couple of others and then include this file at the beginning of the ".cpp" files. It does save on some typing and includes the header files that I use most often.

For future reference "Windows.h" is not a standard C++ header file and not everyone can use it. If you are writing the program for your-self or school that uses computers with the Windows operating system that is OK.

For further comments I will have to load up the program and see what happens.

Hope that helps,

Andy
Hello kreezy,

The first thing I noticed is that the main menu has no way to exit the program.If the idea is that the program runs all the time this is fine, but you may want to add an exit choice for testing while writing the program.This does not have to show up in the menu choices.

Next I found that the menu prints out 10 choices, but there are 11 available because when I entered 11 to see what would happen it told me that I chose a Barbie Doll that was not listed on the menu.

In the file "vendingMachine.cpp" in the function "PrintAllItems()" the for loop starts at 1 when it should start at zero.Keep in mind that C++ is zero based meaning containers like "string"s, "vector"s, "list"s and "array"s all start their indxing at zero.If you want the for loop to start at 1 then you will have to make the container one larger than you need or set up the prgram to always skip element zero.

The prompt for entering the money was a problem the first time because I did not understand it correctly.After a couple of attempts I got it write.You might want to consider revising the prompt.Just a suggestion.

When the menue prints for me the item numbers are out of order.It starts with "Beverages" at 4 followed by "Chips" with 1 and finishes with "toys" at 9. Not sure where the problemis yet, but it looks better when the numbers are in proper order.Just a small thing.

In the program I found "Sleep(5000);". This is only available to Windows computers and not available to everyone. I have found this to be a good replacement for "Sleep" std::this_thread::sleep_for(std::chrono::seconds(5)); // Requires header files "chrono" and "thread" . The only thing you have to worry about is the number 5. This is the number of whole seconds the code will pause for.

After that the use of "System" anything should be avoided. "CLS" is not available to everyone. For "pause" I generally use this code:
1
2
3
4
// The next line may not be needid. If you have to press enter to see the prompt it is not needed.
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.
std::cout << "\n\n Press Enter to continue";
std::cin.get();

To clear the screen I use a function, but it uses the "Windows.h" header file , so it is only for personal use.

From what I can tell the rest of the program appears to work OK.

Hope that helps,

Andy
Thanks a lot from everyone who responded. This project was made without little to no bug testing/extra research. I'll make sure to do more bug testing, and I'll avoid using classes when not needed now :D
Topic archived. No new replies allowed.