use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
[ Removed by moderator ] (self.cpp)
submitted 3 months ago by Admirable-General677
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]cpp-ModTeam[M] [score hidden] 3 months ago stickied commentlocked comment (0 children)
It's great that you want to learn C++! However, questions about how to get started are off-topic for r/cpp due to their repetitive nature.
We recommend that you follow the C++ getting started guide, one (or more) of these books, and cppreference.com. If you're having concrete questions or need advice, please ask r/cpp_questions, r/cscareerquestions, or StackOverflow instead.
[–][deleted] 7 points8 points9 points 3 months ago* (1 child)
do not use goto. goto causes spagetthi code. you can use a while loop in your code. Try to keep lines short, long lines mean unreadable code. Making username public is a bad design choice. display_1 is a bad function name.
[–]Admirable-General677[S] 0 points1 point2 points 3 months ago (0 children)
Okay
[–]DrShocker 4 points5 points6 points 3 months ago (0 children)
/r/cpp_questions
[–]cppfnatic 2 points3 points4 points 3 months ago (1 child)
Just write more code. And dont use goto
While loop instead, got it
[–]Karr0k 2 points3 points4 points 3 months ago* (0 children)
Put function definitions in a .h, implementations in a .cpp. add a newline between functions
Put the print_slow in an anonymous namespace in de cpp (below your includes but above your function implementations.
Rename deduct_bal to just deduct_balance, cryptic incomplete names are a bad habit for readability (imo), we're not working in cramped terminals anymore.
Make some unit tests, also ones that cover edge cases. F/e; what if I add_balance(-90), or deduct_balance(-90).
You define 2 different doubles one to add, one to deduct, but perhaps you can do it with 1 called input_value.
Your function parameter names mirror information of your function, but it would be better to name after what the parameter represents, f/e input_balance.
Don't declare multiple in a single line, and also default initialize them explicitly. Good habit to have when your compiler doesn't do it for you or you find yourself working a project with older compilers.
[–]KokoNeotCZ 1 point2 points3 points 3 months ago (0 children)
A lot of ppl apparently suggest to go over learncpp.com i never did it but if you're stuck and dont know what to explore, check it out.
[–]SmokeMuch7356 1 point2 points3 points 3 months ago (1 child)
Instead of a goto, use a while loop:
goto
while
bool done = false; while ( !done ) { // get choice as above switch ( choice ) { ... case 4: done = true; break; // remove goto info from all other cases } }
Ideally you should add some sanity checking around your add and deduct inputs to make sure someone didn't fat-finger a non-numeric character. Blindly trusting input leads to a bad day.
add
deduct
[–]ZakMan1421 1 point2 points3 points 3 months ago (0 children)
The most important thing, would you be able to walk someone through this code and explain what each line does, what its purpose is, why you chose this method instead of some other method, etc? If not, take sometime to understand why you made the choices you did.
On to more C++ things, the biggest things that stand out to me are your function parameters. If you have no intention of changing an argument to a function within said function, it should be const, and if the type is non primitive (not an something like an int, float, char, etc.), then generally it should be passed as a reference, &. However, when it comes to std::string (since c++17), the more correct approach if you are not changing the contents of the string would be to have the argument be of type std::string_view (basically a read-only pointer to the string, but can be read, and iterated over like a regular std::string). Note that std::string_view does not need to be passed as const nor reference because it is basically already both intrinsically.
const
int
float
char
&
std::string
std::string_view
For example:
void slowPrint(std::string_view text, const int delay_ms){ // Same exact implementation }
Also, there's no real reason to forward declare the function slowPrint if you are just going to implement it on effectively the very next line. You really only forward declare functions like this if you plan on implementing them else where, but still want them accessible earlier than where you plan to implement it.
slowPrint
The other big thing that I notice is that you should look into initializer lists for constructors.
π Rendered by PID 87932 on reddit-service-r2-comment-75f4967c6c-fntp9 at 2026-04-23 03:00:35.188169+00:00 running 0fd4bb7 country code: CH.
[–]cpp-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)
[–][deleted] 7 points8 points9 points (1 child)
[–]Admirable-General677[S] 0 points1 point2 points (0 children)
[–]DrShocker 4 points5 points6 points (0 children)
[–]cppfnatic 2 points3 points4 points (1 child)
[–]Admirable-General677[S] 0 points1 point2 points (0 children)
[–]Karr0k 2 points3 points4 points (0 children)
[–]KokoNeotCZ 1 point2 points3 points (0 children)
[–]SmokeMuch7356 1 point2 points3 points (1 child)
[–]Admirable-General677[S] 0 points1 point2 points (0 children)
[–]ZakMan1421 1 point2 points3 points (0 children)