Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
41 votes
Accepted

BMI calculator in python using if statements

This kind of programming exercice, despite its apparent simplicity, is a good opportunity to learn various things. Style Python has a Code Style guide called PEP 8. If you begin with Python, I ...
SylvainD's user avatar
  • 29.2k
36 votes

Car crash reaction time

Some of the numbers might seem plucked out of thin air but they aren't Still better have them explained. I can understand 3.6 and even ...
vnp's user avatar
  • 56.5k
30 votes

Beginner C++ calculator

Welcome! Here is some feedback, in no particular order. Avoid using namespace std This advice is often repeated for good reason. See also: code guidelines SF.6. ...
esote's user avatar
  • 3,770
19 votes
Accepted

Poor man's JIT using nested lambdas

Is there a better way to do this? Well, you have dynamic dispatch and yet another scattered island of memory for every single token. That is massively inefficient. A simple way to more efficiency is ...
Deduplicator's user avatar
  • 19.3k
18 votes

Car crash reaction time

I suggest breaking the code into functions, so you can easily import your code into a Python shell and test that your computation is exact (and not just thinking it ...
301_Moved_Permanently's user avatar
16 votes

Simple calculator in C#

I'm going to go over a few things in this answer, hopefully it makes them simple enough. Then, at the end, I'm going to go way overboard and significantly over-engineer this programme while still ...
Der Kommissar's user avatar
15 votes

C++ calculator using classes

Unless you'll be maintaining an accumulated number for multiple operations, this may not be the best use of classes. For your code, you'd get the same effect by just performing these calculations ...
Jamal's user avatar
  • 34.9k
15 votes

A Simple Calculator

Variable Names Your variable names need some improvement. When I see x, y, and z, I ...
AJNeufeld's user avatar
  • 33.7k
13 votes
Accepted

Simple python calculator

For a beginner this is pretty good. But, there are three glaring problems with it. You should use a 'main' function. You should use a dictionary. operators ...
Peilonrayz's user avatar
  • 43.4k
13 votes
Accepted

Super calculator in C

You are using textual strings to represent numbers. This is not ideal for the processor. It is better to store the numbers as arrays of 32 or 64-bit unsigned integers, depending on the type of CPU. ...
G. Sliepen's user avatar
  • 56.8k
13 votes

Car crash reaction time

It crashes if user input for speed_ms is not integer If user presses any key before t = input("GO!! ") his reaction time is ...
Lau's user avatar
  • 231
13 votes
Accepted

Console calculator for 2 numbers at a time

Some rules of thumb: If you have your entire program in a single method (Main(), in this case), there are some design considerations you should probably revisit. ...
Jesse C. Slicer's user avatar
12 votes

Circumference and Area of a Circle in COBOL

Is Lynda that woman from LinkedIn, or just some mate of yours? I wonder how good a teacher she is, and what her intent is. Is it to learn COBOL, or GnuCOBOL. The reason I say that is that COBOL has ...
Bill Woodger's user avatar
12 votes
Accepted

Beginner's simple calculator

Welcome to the world of beginner Python programming, and programming in general! Python is a nice language to learn and start out with! Allow me to give you some tips and pointers, with the hope ...
Thomas Ward's user avatar
  • 2,518
12 votes

Car crash reaction time

If it's wet, the friction_coefficient will be lower. Which means that Bd will be lower (which is probably wrong). It's ...
Reinstate Monica's user avatar
12 votes

Car crash reaction time

player_1 is read and assigned but never used. If the user misspells wet (e.g. as Wet or as <...
Toby Speight's user avatar
  • 75.7k
12 votes
Accepted

Basic calculator in Python

If you don't want any if statements then you can do the same with the operator library and a dictionary. This is by using the <...
Peilonrayz's user avatar
  • 43.4k
12 votes
Accepted

C++ arithmetic on two numbers

Code formatting Format your code to improve readability and hence maintainability. DRY (Don't Repeat Yourself) Principle You have a lot of places with duplicate code. You should try to avoid this. ...
Vadim Ovchinnikov's user avatar
12 votes
Accepted

Calculator in C++

I have some suggestions here: Using switch/case instead of if/else looks a little better and slightly faster as also mentioned in the comments. You could definitely work on formatting your code it ...
Syed M. Sannan's user avatar
11 votes
Accepted

Basic calculator that takes 2 numbers and does an operation with them

The main issue with your code is repetition. The 4 methods calculating the result based on user input are sketched in the same way: ...
Tunaki's user avatar
  • 9,243
11 votes
Accepted

Velocity, Distance and Time Calculator

...
200_success's user avatar
11 votes

C++ - algebraic expressions calculator by addition

Namespaces You almost never want to write using namespace std; - this is a very common code complaint on this site with C++. The two main reasons are: it's good ...
JNS's user avatar
  • 421
11 votes
Accepted

Reverse Polish Notation (RPN) Calculator

The initial approach is full of redundant if conditions for capturing float numbers and duplicated set of statements (...
RomanPerekhrest's user avatar
11 votes
Accepted

C# Intermediate Calculator Program

First of all, let's review some semantics that make the program a bit clumsy: while (loopInt == false) > while (!loopInt) ...
Yotam Salmon's user avatar
10 votes
Accepted

Parabola calculations

I see a number of things that may help you improve your code. Avoid macros The macros _X_UNTIL_Y and _ATOI do not help with ...
Edward's user avatar
  • 66.4k
10 votes
Accepted

Circumference and Area of a Circle in COBOL

For the working Storage, I would suggest 2 changes align the picture clauses align the 05 directly under name on the 01 tag e.g. ...
Bruce Martin's user avatar
10 votes
Accepted

Homework to display a square and calculate tips

The code is not self-documenting, because the problem description is non-trivial and involves what you'd call "business logic". That is, you're not trying to perform some technical operation (like a ...
Pimgd's user avatar
  • 22.3k
10 votes

Basic calculator program in Python as a beginner

Thanks for asking your question! I'll try and give a concise answer to the main issues with your code. Overall it is well done for a beginner. First, I'll address the code block you're having trouble ...
Brandon H. Gomes's user avatar
10 votes

Calculator final project in Python

You are using function calls as if they were goto labels. That is a huge sin: it makes your program spaghetti code. If you want a loop, then write a loop. For example, ...
200_success's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible