Return a value from a function - C++ Function

C++ examples for Function:Function Return

Description

Return a value from a function

Demo Code

#include <iostream>
using namespace std;
char cfunc(int i) {
   if(i == 0)//from ww  w.  ja v a2 s  .  c  om
      return 'a';
   if(i == 1)
      return 'g';
   if(i == 5)
      return 'z';
   return 'c';
}
int main() {
   cout << "type an integer: ";
   int val;
   cin >> val;
   cout << cfunc(val) << endl;
}

Result


Related Tutorials