Main() function passes variables to receiving function, which calculates and prints values related to those passed variables. - C++ Function

C++ examples for Function:Function Parameter

Description

Main() function passes variables to receiving function, which calculates and prints values related to those passed variables.

Demo Code

#include <iostream>
using namespace std;
#include <iomanip>
int check_grade(char lgrade, float average, int tests);
int main()/*w  w  w.  j a  v  a2s  . c  om*/
{
   char lgrade;   // Letter grade.
   int  tests;    // Number of tests not yet taken.
   float average; // Student's average based on 4.0 scale.
   cout << "What letter grade do you want? ";
   cin >> lgrade;
   cout << "What is your current test average? ";
   cin >> average;
   cout << "How many tests do you have left? ";
   cin >> tests;
   check_grade(lgrade, average, tests);  
   return 0;
}
int check_grade(char lgrade, float average, int tests)
{
   switch (tests)
   {
      case (0):
      {
         cout << "You will get your current grade " << "of " << lgrade;
         break;
      }
      case (1):
      {
         cout << "You still have time to bring " << "up your average";
         cout << "of " << setprecision(1) << average << "up. Study hard!";
         break;
      }
      default:  {
         cout << "Relax. You still have plenty of " <<  "time.";
         break;
      }
   }
   return 0;
}

Result


Related Tutorials