University of Cambridge >  Engineering Department >  computing help >  Languages >  C++

C++ "function" teaching aid



Look at the following code. There's a main function inside which there's a call to a function called doubling that returns twice the given number. You need to write a prototype for the doubling function and complete the function itself. Type something in the boxes so that the compiled code would work
#include <iostream>
using namespace std;

// Add doubling's prototype here


int main() {
   int i=7;
   int num;
   num=doubling(i);
   cout << num << endl; // this should print 14
}

// this function should return double the input parameter
 doubling () {
   int i=num*2;
   
}


P.S. the checker isn't foolproof. The best way to check your answer is to put the program into a file, compile it, then run it!
© Cambridge University Engineering Dept
Information provided by Tim Love (tpl)
Last updated: December 2010