Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.
42 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 ...
user avatar
  • 28.7k
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 ...
user avatar
  • 53.1k
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. ...
user avatar
  • 3,760
24 votes

My first calculator

Input validation You do absolutely no input validation when the user enters an integer. If the user enters a non-integer value, like foo, or ...
user avatar
22 votes
Accepted

Three-function calculator

I'll blame the extra-weird broken indentation on copy/paste difficulties, and ignore that. There are as many ways to write a calculator as there are programmers willing to write one. So I'm not going ...
user avatar
21 votes
Accepted

"The python that ate a calculator"

I suppose you don't indent the printf debug lines to make them easier to spot. That's a sensible idea (although not one I've seen before). However, I treat Code ...
user avatar
  • 9,523
20 votes
Accepted

Body Mass Index Calculator

The reason it seems messy is because you have one function doing multiple things. So what does your function do? It queries the DOM for elements containing the input. It calculates the BMI based on ...
user avatar
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 ...
user avatar
  • 17.1k
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 ...
user avatar
17 votes

"The python that ate a calculator"

This is very nicely written, pleasure to read. Most of my comments will concern usability and readability. The NONE operator ...
user avatar
  • 107k
17 votes
Accepted

Simple calculator with classes in C++

Welcome to C++. A few notes: When working outside of a toy project, avoid using namespace std. For why, see here. In addition, when working outside of a toy ...
user avatar
15 votes
Accepted

Calculator using class templates

Don't flush where you don't need to. Flushing is expensive, so don't use std::endl unless you need it. Nearly always, the shorter ...
user avatar
  • 17.1k
15 votes
Accepted

Newborn pythonic calculator

This looks pretty nice! I have only a few minor nitpicks and practical tips for you. Returning boolean values directly I'm a bit surprised by this: ...
user avatar
  • 107k
15 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 ...
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 ...
user avatar
  • 34.7k
14 votes
Accepted

Very basic calculator using methods

Nice job! I hope you find the comments below useful as you progress. Variable names: Try to have variable names which describe what the variable actually represents or holds. For example, I have no ...
user avatar
  • 4,849
14 votes
Accepted

Simple calculator in C

I must say, I respectively disagree with @ishyfishy's example of the addition function. Although, I do agree with the point about splitting the arithmetic ...
user avatar
  • 13.2k
13 votes
Accepted

Simple calculator

A few notes: You see those global variables that you have at the top? ...
user avatar
  • 21.6k
13 votes
Accepted

Binary Calculator in Java

Style I'm sorry for making it personal here, camelCase, but the preferred styling for function names is that they're, well, camelCased. (Apologies for the bad pun). So not ...
user avatar
  • 22.2k
13 votes

Did not pass the interview about an RPN Calculator

I don't know how your assignment looked exactly, so some of the below may be misguided criticisms. I've just tried to poke as many holes in the code as possible; fair or otherwise. Something will ...
user avatar
  • 32.9k
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 ...
user avatar
  • 41.6k
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. ...
user avatar
  • 32.6k
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 ...
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. ...
user avatar
12 votes

Simple Console Calculator

A CLI-based calculator is often a good way to prepare one for bigger programming tasks, as there are just so many ways of doing it, catering for beginner to advanced implementations. I happen to have ...
user avatar
  • 19.1k
12 votes

My first calculator

Here are a few comments: Read PEP 257, which explains docstrings. Docstrings are the preferred way to document functions in Python, not comments above the definition. You’re importing the math module ...
user avatar
  • 8,465
12 votes

Simple Java calculator with two operands

Your code Simple is nice. But it would have been good to decompose your solution to multiple methods, for example at least: a method to read a double a method to ...
user avatar
  • 107k
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 ...
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 ...
user avatar
  • 2,488

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