← C++ from Scratch Lesson 27 of 62 · 5 XP

Warm-up: the twice function warm-up

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

A function is a piece of code with a name. The result type goes before the name, and return gives back the answer:

int plusOne(int x)
{
    return x + 1;
}

The function is written before main and called inside it: plusOne(4) gives 5.

Task. Finish int twice(int x) that returns the number doubled. main already reads the number and prints twice(n).

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.