Not every function needs to produce a value. Some functions perform an action, such as displaying a heading. A return type of void means the function returns no value to its caller.
#include <iostream>
void printDivider() {
std::cout << "---\n";
}
int main() {
printDivider();
std::cout << "Schedule\n";
printDivider();
return 0;
}
The two calls display the same divider without duplicating its output statement in main. A void function may simply reach its closing brace. It can also use return; to end early, but it must not return an integer or another value.
Notice that each call stands alone as a statement: printDivider();. Do not try to place this call after std::cout << or assign it to an integer variable. There is no returned value to insert or store; the function itself performs the output action.
As with value-returning functions, a definition does nothing until called. A function can also accept parameters while returning void; its input and its return type answer different questions.
Your starter calls printWelcome twice, but its empty body currently does nothing. Add the welcome output inside that body, not in main. The first call will print the line and return to main; the second call will run the same statement again. You write the message once, while the caller decides how often it appears.
printWelcome that prints Welcome to the workshop followed by a newline. The two supplied calls should produce that line twice.Edit main.cpp, press Run to inspect the Console, then Submit to check your work.