Introduction to Simple Arithmetic Operations

Welcome back! In the previous lesson, you explored how to define and manage numeric variables in COBOL. Understanding numeric data is essential, as many business applications rely on accurate calculations. Now, it's time to take a step further by learning about simple arithmetic operations in COBOL. This is a fundamental skill that will enable you to perform essential calculations such as addition and subtraction.

What You'll Learn

In this lesson, you will learn to perform basic arithmetic operations on numeric variables in COBOL. Specifically, we will cover the following topics:

  • How to add and subtract numeric variables using COBOL syntax.
  • How to display the results of these operations.

Let's delve into these topics through an example. Consider the following COBOL program that demonstrates adding and subtracting two numeric values:

Note: When displayed, the numbers are padded with leading zeros to fill the entire field. This is a common practice in COBOL to ensure that the output is aligned correctly. However, the actual value stored in the variable does not contain these leading zeros. For simplicity, we will ignore the leading zeros in the output and focus on the actual values from now on.

Breaking Down the Code
Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal