Math Functions and Operators in Dev-C++

2013-06-10

In this C++ tutorial, I’ll be teaching you how to do math functions in C++. I’m going to use the addition and subtraction operators and I’m also going to show you some other mathematical functions.

First, we’re going to need to include our library by entering the above coding.

Next, we’re going to enter two integers, along with Enter commands for those integers. Now, I’m going to show you how to add a real number.

Using this example, I am going to show you how to compile a file. I am going to select Compile & Run from under the Execute menu.

In the Compile Progress window, I am going to select Log. This will then bring up the .exe file where you can enter any two numbers that you want. I am going to enter 23 and 12:

Instead of adding, you can also have the program subtract, divide, and multiply. You can do anything you want, really; this is just a simple math function in C++. Now, I am going to show you how to use a math function in Dev-C++.

For this, we only need one variable. I also need to create an alphabetical value. I am going to choose Z, and equal it to a value of 2.

Next, I need to take the square of a number. I’m going to use a float function and set the result to be the power of the number that I want to square.

Next, I’m going to Execute the Compile & Run function again.

As we see here, I have an error. I forgot to add the following math function:

After correcting this error, I am going to try to Compile & Run again. You can see in the screenshot that it worked! The command will tell me to enter any number I wish.

I am going to enter 16. The result, accurately following the function’s logic, will be 256.