课程: Complete Guide to C++ Programming Foundations

免费学习该课程!

今天就开通帐号,24,100 门业界名师课程任您挑!

Writing functions

Writing functions

- [Instructor] Let's go through a quick exercise where we will write a few functions to improve this simple program, which prints the score of some player. Right now, we have a player named Alex who scored 75 points! Our goal is to move some of this logic into functions. Pretty simple, right? In this exercise, we want to write our code in a top-down fashion, which means we will start by modifying the main function to use functions that we haven't implemented yet. This approach allows us to focus on how we want to use the functions before we worry about how they are implemented. So, let's look at the main function. We want to refactor this code by using three functions. One, to get the player's name, one to calculate the player's score, and one to display the score. First, let's modify the main function to use these functions as if they were already written. We'll start at line nine by calling a function named getplayerName to retrieve the player's name. (keyboard keys clicking) You…

内容