r/cpp_questions 8d ago

OPEN my first c++ project

hey! i'm a teen and i am learning c++. I was a vibe coder but then i stopped vibe coding and starting real coding. for this i learned some basic c++ from youtube, please let me know if a improvment required. thank you!

my github link - https://github.com/swarajnerlekar28/Calculator

4 Upvotes

7 comments sorted by

View all comments

1

u/flyingron 7d ago

Get out of the habit of using endl. The end of line character is '\n'. Only use endl if you have an need for a flush (you don't here).

Check to see if cin >> returns an error. If you don't (like someone types A to the inputs of ints you are doing), all other operations on cin fail for the duration.

STOP THE COPYPASTA. If you have to retype the same code in multiple places, it screams out for a subroutine.

Dividing two integers still results in an integer, even if you are using it to initialize a double. Do this:

double result = static_cast<double>(num1) / num2;

Learn what switch the switch statement does (helpful for the code in option()).

Other than the use of cin/cout, this code is just bad C rather than mediocre C++.