while, sentinel, if, switch

This is a discussion on while, sentinel, if, switch within the C++ Programming forums, part of the General Programming Boards category; I'm getting error C2601: 'printreport' : local function definitions are illegal can anybody help with this:// This program will compute ...

  1. #1
    Unregistered
    Guest

    Question while, sentinel, if, switch

    I'm getting error C2601: 'printreport' : local function definitions are illegal

    can anybody help with this:// This program will compute and print a statement for each patient
    // showing the number of days in the hospital, the room type, and
    // the total room charge, based on room type, any charges for
    // telephone or television, and also the total charge including
    // roomcharge, telephone charge, and television charge, and will
    // repeat the process until the sentinel value is entered.

    //*~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
    //* The includes *
    //*~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

    #include <iostream.h>
    #include <iomanip.h>


    //*~~~~~~~~~~~~~~~~~~~~~~~~~~~*
    //* The constants *
    //*~~~~~~~~~~~~~~~~~~~~~~~~~~~*


    const double PRIVATE_ROOM =125.00;
    const double SEMIPRIVATE_ROOM =95.00;
    const double WARD =75.00;
    const double PHONE_CHARGE =1.75;
    const double TV_CHARGE =3.50;
    const int SENTINEL =0;


    //*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
    //* The functions *
    //*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

    //GetData funtion
    void getdata (int &days, char &rmType, char &tele, char &tv);
    //prompts for room type, telephone and tv

    //Telephone Charges Calculator
    double telephonechgs(int days, char tele);

    //Television Charges Calculator
    double televisionchgs (int days, char tv);

    //Total Patient Billing Calculator
    void patientcharge (int days, char rmType, double &roomrate, double telephone, double television);

    void printreport(int days, char rmType, double roomrate, double telephone, double television, double &totalroom, double&totaltelephone, double &totaltelevision);
    //prints the total of all charges

    //*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
    //* The main program *
    //*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

    int main (){

    int days; //number of days in the room
    char rmType; //type of room: Private SemiPrivate or Ward
    char tele; //yes or no for telephone in the room
    char tv; //yes or no for tv in room
    double roomrate; //patient room fee * days
    double telephone; //total telephone charge * days
    double television; //total television charge * days
    double totalroom;
    double totaltelephone;
    double totaltelevision;


    getdata (days, rmType, tele, tv);
    //asks for 4 inputs, days of stay, room type, if they have a phone ortelevision
    telephone=telephonechgs (days, tele);//calculates the phonecharges
    television=televisionchgs (days, tv);//calculates the televisioncharges
    patientcharge (days, rmType, roomrate, telephone, television);
    //calculates the total bill
    printreport (days, rmType, roomrate, telephone, television, totalroom, totaltelephone, totaltelevision);
    //prints report for daily charges


    while (days != SENTINEL) //beginning of loop
    {


    getdata (days, rmType,tele,tv);
    totalroom = totalroom+roomrate;
    totaltelephone = totaltelephone+telephone;
    totaltelevision = totaltelevision+television;
    printreport(days, rmType, roomrate, telephone, television, totalroom, totaltelephone, totaltelevision);


    }

    return 0;

    }

    //*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
    //* The functions *
    //*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

    //Function GetData
    void getdata (int &days, char &rmType, char &tele, char &tv)

    {
    cout<<"Number of Days in hospital " ;
    cin>>days;
    cout<<"Type of room (P=Private, S=Semi Private, W=Ward) ";
    cin>>rmType;
    cout<<"Does the patient have a telephone ? ";
    cin>>tele;
    cout<<"Does the patient have a television ? ";
    cin>>tv;
    cout<<endl;
    return;
    }


    //Telephone Charges
    double telephonechgs(int days,char tele)
    {
    double telephone;

    if ((tele =='Y') || (tele =='y'))

    {
    telephone = PHONE_CHARGE * days;
    }
    else
    {
    telephone =0.00;
    }
    return telephone;
    }


    //Television Charges
    double televisionchgs (int days,char tv)
    {
    double television;

    if ((tv =='Y')||(tv =='y'))
    {

    television= TV_CHARGE * days;
    }
    else
    { television=0.00;
    }
    return television;
    }


    //Patient Charge
    void patientcharge (int days, char rmType, double &roomrate, double telephone, double television)

    {
    switch (rmType)
    {
    case 'P':
    case 'p': roomrate = PRIVATE_ROOM*days;
    break;
    case 'S':
    case 's': roomrate = SEMIPRIVATE_ROOM*days;
    break;
    case 'W':
    case 'w': roomrate = WARD*days;
    break;

    default: cout<<"Invalid entry - No such type of room"<<endl;

    }

    //Print Report
    void printreport(int,char,double,double,double,double &,double &,double &)
    {

    cout<<setiosflags (ios::fixed|ios::showpoint|ios::right)<<setprecisi on (2);
    cout<<"******************************************* *******************"<<endl;
    cout<<" Community Hospital "<<endl<<endl;
    cout<<" Patient Billing Statement "<<endl<<endl<<endl;
    cout<<"Number of days in hospital ";
    cout<<days<<endl;
    cout<<"Type of room: ";

    }
    switch (rmType)
    {
    case 'P':
    case 'p': cout<<"Private";
    break;
    case 'S':
    case 's': cout<<"SemiPrivate";
    break;
    case 'W':
    case 'w': cout<<"Ward";
    break;

    }

    cout<<endl;
    cout<<"Room Charge ";
    cout<<setw(6)<<roomrate<<endl;
    cout<<"Telephone Charges ";
    cout<<setw(6)<<telephone<<endl;
    cout<<"Television Charges ";
    cout<<setw(6)<<television<<endl;
    cout<<" TOTAL DUE $";

    cout<<endl<<endl;

    return;

    }

    jhm1357@pcstarnet.com

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Your missing a closing }

    Code:
    void patientcharge (int days, char rmType, double &roomrate, double telephone, double television) 
    
    { // 1 opened
    switch (rmType) 
    { // 2 openend
    case 'P': 
    case 'p': roomrate = PRIVATE_ROOM*days; 
    break; 
    case 'S': 
    case 's': roomrate = SEMIPRIVATE_ROOM*days; 
    break; 
    case 'W': 
    case 'w': roomrate = WARD*days; 
    break; 
    
    default: cout<<"Invalid entry - No such type of room"<<endl; 
    
    } // one opened
    
    // need another closing paren here
    //Print Report 
    void printreport(int,char,double,double,double,double &,double &,double &) 
    {
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  2. Switch
    By cogeek in forum C Programming
    Replies: 4
    Last Post: 12-23-2004, 05:40 PM
  3. Sentinel while loop and errors.
    By lollypop in forum C Programming
    Replies: 12
    Last Post: 10-19-2003, 12:40 PM
  4. Switch Case
    By FromHolland in forum C++ Programming
    Replies: 7
    Last Post: 06-13-2003, 03:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21