官术网_书友最值得收藏!

Basic functions

We learned at the beginning of this chapter that the first electronic calculator had four basic functions: addition, subtraction, multiplication, and pision. We will be working on programming each of these functions, and we will also learn a fifth mathematical function that we can program for our calculator called modulo.

Through the beginning of this chapter, we will use the addition() function as our example. Once we have created and tested an addition() function that does what we want it to, we will then build our other functions.

Let's return to our example of the addition function in Chapter 2, Variables, Functions, and Users. Recall how we programmed this function:

The addition function in the preceding screenshot does perform proper addition and prints the answer. However, there are problems with designing an addition() function this way. One problem is that the program can only add the same two numbers over and over again. Another problem is that, in this program, we are only using one mathematical operation (addition). This addition() function is too inflexible on its own; we need to design a function that is more user friendly.

To design a better mathematical function, we need to solve the problem of user-inputs by letting the user change the numbers in the calculation. We also need to design a calculator where the user has mathematical functions other than addition that can be performed.

主站蜘蛛池模板: 武穴市| 当涂县| 姜堰市| 安塞县| 祁阳县| 三台县| 江门市| 天水市| 淳化县| 陇南市| 乌拉特后旗| 彭州市| 永嘉县| 天镇县| 寿宁县| 彝良县| 屯昌县| 若尔盖县| 富蕴县| 于田县| 张家口市| 奈曼旗| 汽车| 罗江县| 九江市| 平远县| 尼勒克县| 鄂托克前旗| 呼伦贝尔市| 徐闻县| 双鸭山市| 乌兰浩特市| 乐平市| 陆良县| 沁水县| 清水河县| 河南省| 三穗县| 高唐县| 武夷山市| 福建省|