It can be pretty useful for modularizing output.
I'll provide you with an example:
#include <iostream>
#include <string>
using namespace std;
void displayMessage(string fName, string mName, string lName, string id);
int main() {
string student[4] = { "Mike", "L.", "Jason", "c23459i" };
displayMessage(student[0], student[1], student[2], student[3]);
return 0;
}
void displayMessage(string fName, string mName, string lName, string id)
{
double PI = 3.14159265359;
cout << "Student " << " information:"
<< "\nFirst name: " << fName
<< "\nMiddle Initial: " << mName
<< "\nFirst name: " << lName
<< "\nID: " << id
<< "\nThe Circumference of a circle with the radius of 2: " << (2*PI*2);
}
You can use void functions IF you don't need to return a value. If you plan to do calculations and return a value such as an int, use a function declaration with the return type of int.
out
params. – Akeylah