Filling In Two Function Bodies

Easy

This exercise is the other way round from every one before it. main is already written for you, and it will not change: it calls two functions that do not work yet, and your job is to make them work. Do not edit main, and do not move the two functions below it, because a definition placed after its call is a function the compiler has not heard of yet. print_header takes nothing and returns nothing, which is what the void before its name and the (void) between its parentheses each say, and it must print two lines, "clamp report" and then twelve dashes. clamp takes three int values and returns one: low when value sits below low, high when value sits above high, and value itself when it already lies between the two. That is the whole of clamping, and the shape is already in the template as two ifs and a final return, each of them currently returning the wrong thing. Leave every one of those returns in place and change what it hands back, because a non-void function has to return a value on every path through it, and falling off the end and then using the result is undefined behaviour rather than a zero. Watch the boundaries: a value exactly equal to low or to high is already inside the range and must be returned untouched, so the comparisons are < and >, not <= and >=. main reads the three numbers with one scanf and checks its conversion count first, exactly as chapter 2 taught, and prints an error line when three numbers did not arrive. Note that the header prints before that check, so it appears on every run including the failing one. Every path out of main returns 0, the error path included, because the checker compares what you print and reports a nonzero exit status as a failure however right the output looks.

Success Criteria

Your code must pass 5 test case(s) to complete this exercise. 3 hint(s) are available if you need help.

Sign in to track your progress

You can work on exercises as a guest, but sign in to track your progress and save your submissions.

This platform is built by its community

Every lesson, project, and tool on HelloC++ is funded by sponsors. Join them and help shape what we build next.

Become a Patron