Question: C++ undefined The scaffold code below contains a set of commands that is repeated three times. Modify the code so that the repeated commands are

C++C++undefined The scaffold code below contains a set of commands that isrepeated three times. Modify the code so that the repeated commands areundefined

The scaffold code below contains a set of commands that is repeated three times. Modify the code so that the repeated commands are contained in a user-defined function rather than in the body of main. This will require: 1. Creating a function definition with an appropriate name and return type. Its parameter list should be empty. 2. Copying the repeated block of code into the function body. 3. Adding a variable definition for nextNumber in the function body, so that the function can assign a value to it. 4. Adding a return statement to the function that sends the value of the variable nextNumber back to the main program. 5. Replacing each block of repeated commands with a single line of code that calls your new function and adds the result to sum. For example, if you named your function GetUserinput, then the line "sum = sum + nextNumber;" would become sum = sum + GetUserInputo; The final program behavior should be exactly the same as the original scaffold. 1 // This program requests three integers 2 // from the user and then sums them 3 // together 4 5 #include 6 using namespace std; 7 8 int main() { int sum=; 10 int nextNumber; 11 12 cout > nextNumber; 16 sum += nextNumber; 17 18 cout > nextNumber; 22 sum += nextNumber; 23 24 cout > nextNumber; 28 sum += nextNumber; 29 30 cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!