// Mr. Minich
// CMPSC 201
// Ch. 6 Demo Program #1
// January 30, 2000 // Purpose - to illustrate the use of void functions (functions that do not return a value). // One void function has a parameter and the other does not.

#include <iostream> using namespace std; void printMyName(int numOfTimes); // prints the user's name void printSchoolName(); // prints the name of the user's school
// notice that semicolons are necessary at the end of function // prototypes statements. Both of the functions are "void functions" // since they do not "return" values to the function that calls them. int main() { int userInput = 0; // user's inputted number cout << "Enter an integer: "; cin >> userInput; printMyName(userInput);
// The statement above is a "call statement". It simply calls // the function PrintMyName which was declared with a function // prototype at the top of the program. When C++ encounters this // call statement, it transfers execution control to the function // where it is defined at the bottom of the program. The variable // UserInput is sent as an argument. printSchoolName();
// This is another call statement that calls the function PrintSchoolName. // No argument is sent since none is specified in the parentheses.
return 0; } // end of main void printMyName(int numOfTimes) // this function prints "Mr. Minich" a specified number of times { for (int i = 1; i <= numOfTimes; i++) { cout << "Mr. Minich" << endl; } } // end of printMyName void printSchoolName() // this function prints "Penn State University"
{ cout << "Penn State University" << endl; } // end of printSchoolName