C++ main() function passes these variables to the receiving function

Introduction

calculates and prints values related to those passed variables

#include <iostream>
using namespace std;
#include <iomanip.h>
check_grade(char lgrade, float average, int tests);
int main()//from w  ww  .jav  a 2s.c  o  m
{
   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;
}
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;
}



PreviousNext

Related