C++ examples for Function:Function Creation
Pass three local variables to functions.
#include <iostream> using namespace std; #include <iomanip> int pr_init(char initial); // Prototypes discussed later. int pr_other(int age, float salary); int main()/*ww w.j a v a2 s . c o m*/ { char initial; // Three variables local to main(). int age; float salary; // Fill these variables in main(). cout << "What is your initial? "; cin >> initial; cout << "What is your age? "; cin >> age; cout << "What is your salary? "; cin >> salary; pr_init(initial); pr_other(age, salary); return 0; } int pr_init(char initial) { cout << "Your initial is " << initial << "\n"; return 0; } int pr_other(int age, float salary) { cout << "You look young for " << age << "\n"; cout << "And " << setprecision(2) << salary << " is a LOT of money!"; return 0; }