Gold University of Minnesota M. Skip to main content.University of Minnesota. Home page.
 
 
 

What's inside.

Ta Email

Download Compiler

Final Project

Lab Notes

Office Hours

Schedule

Syllabus

Announcements

Check Grades

 

CSci 1113 Home

 
 

Printer-friendly version

 
Student Fees Calculation - Sentinel Controlled do-while Loop and a switch Statement

% cat fee_switch.cpp
// combine do-while and switch statements
// program assigns student fees

#include <iostream>
using namespace std;

int main()
{
   char student, calc;
   int credits, fee;

   do
   {
     cout << "Enter category: U for undergrad, G for grad, L for Law: ";
     cin >> student;
     cout << "Enter number of credits: ";
     cin >> credits;

     switch(student)
     {
        case 'u':
        case 'U':   fee = credits * 200;
                    cout << "The undergraduate school fee is $" << fee << endl;
                    break;

        case 'g':
        case 'G':   fee = credits * 400;
                    cout << "The graduate school fee is $" << fee << endl;
                    break;

        case 'l':
        case 'L':   fee = credits * 800;
                    cout << "The law school fee is $" << fee << endl;         
                    break;

        default:    cout << "You must enter U, G, or L\n";

      } // end switch
        

     cout << "\nWould you like to do another calculation? Y or N: ";
     cin >> calc;     

   } while( calc=='y' || calc=='Y' );

   return 0;
}
% g++ fee_switch.cpp
% a.out
Enter category: U for undergrad, G for grad, L for Law: U
Enter number of credits: 6
The undergraduate school fee is $1200

Would you like to do another calculation? Y or N: y
Enter category: U for undergrad, G for grad, L for Law: g
Enter number of credits: 6
The graduate school fee is $2400

Would you like to do another calculation? Y or N: Y
Enter category: U for undergrad, G for grad, L for Law: l
Enter number of credits: 6
The law school fee is $4800

Would you like to do another calculation? Y or N: n




 
The University of Minnesota is an equal opportunity educator and employer.
CSci 1113: C++ Programming