// Mr. Minich
// CMPSC 201
// Ch. 6 Demo Program #3
// January 30, 2000 // Purpose - to illustrate the use of functions and a global variable (which is
// dangerous and usually inappropriate.)
#include <iostream> using namespace std; float gradeCurvingFunction(float studentGrade, int curveAmount);
// Technically parameter names do not have to be specified in a function // prototype, only the data types. The following function prototype // would also work, // float gradeCurvingFunction(float, int); float gGlobalGrade = 0; // this is dangerous! // NEVER declare variables above/outside of the main function. // If you do, you had better have a good reason for using what // is called a "global variable". Global variables should be named
// so that they begin with a lowercase 'g'.
int main() { int curveAmount = 0; // the amount of increase cout << "Enter the students grade percentage: "; cin >> gGlobalGrade; cout << "Enter a curve amount of 1, 2, 3 or 4: "; cin >> curveAmount; cout << "Your new grade is " << gradeCurvingFunction(gGlobalGrade, curveAmount) << endl; // A function that returns a value can be used within a // cout statement. return 0; } // end of main float gradeCurvingFunction(float a, int b) { // This function increases a student's grade by a specified // amount of percentage points. // Technically the parameter identifiers a and b do not have // to be the same ones that are used in the function prototype return (a + b); } // end of obtainFavoriteNumber