I'm trying to complete the following problem:
write a problem that generates a table showing tuition and fee costs. the table continues to print up to and including a maximum number of credits that has been input by the user. The program should check that this value is between 12 and 24 inclusive.
the program also requests the user to input the student's residency code and it checks that this value is 1, 2, or 3.
the student's status and the corresponding cost per credit are then determined from his/her residency code as follows:

  1. in county $45.00
  2. out of county 90.00
  3. out of state 180.00

the student fee is detemined as follows: the fee is 40.00 for 12 or more credits and is zero otherwise.

I think I'm really close on this one, but I'm still a little lost.

//******************************************************************************
//  Jamie Insalaco
//
//  CIS-165  C++ Programming I
//
//  Last Update:  November 17, 2004
//
//  Description:  Tuition Schedule
//******************************************************************************
//*****************************PRE PROCESSORS***********************************
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
//**********************************MAIN****************************************
int main ()
{
    ofstream outfile;

    char    status;

    int     credit,
            res_code;

    double  cost_per_credit,
            fee,
            tuition,
            tuition_cost;

    do{
        cout  <<  "Please enter the number of credits you will take:  ";
        cout  <<  "Credits between 12 and 24 credits only";
        cin   <<  credit;}
    while (credit < 12  ||  credit > 24);        


    do{
        cout  <<  "Enter Your Residence Code Number:  ";
        cout  <<  "Code: 1, 2, 3";
        cin   >>  res_code;}
    while!(res_code = 1 || res_code = 2 ||  res_code = 3);

    if(res_code = 1){
        cost_per_credit = 45.00;
        status          = "In County";}
    else if(res_code = 2){
        cost_per_credit = 90.00;
        status          = "Out of County";}
    else{
        cost_per_credit = 180.00;
        status          = "Out of State";}

    if(credit <= 11)
     fee  =  0.00;
    else
     fee  =  40.00;

    tuition  =  cost_per_credit  *  credit;
    tuition_cost  =  tuition + fee;   

    cout  <<  "Direct output to the console (1) or to a disk file (2):  ";
    cin   >>  choice;
    if    (choice == 1)
      outfile.open ( "con" );
    else
      outfile.open ( "a:result.dta" );

    outfile  <<  setiosflags (ios::showpoint | ios::fixed) << setprecision (2);
    outfile  <<  setw(47)  <<  "Tuition Schedule"  <<endl;
    outfile  <<  setw(47)  <<  "----------------"  <<endl  <<endl;
    outfile  <<  "Residency Status:  "  <<  status  <<  endl  <<  endl;
    outfile  <<  "Cost per credit:   "  <<  credit  <<  endl  <<  endl;
    outfile  <<  "Credits"  <<  "Fee"  <<  "Tuition"  <<  "Total Cost"  <<  endl;
    outfile  <<  "-------"  <<  "---"  <<  "-------"  <<  "----------"  <<  endl;
    outfile  <<  credit     <<  fee    <<  tuition    <<  tuition_cost  <<  endl;

    outfile.close ( );

}

Edited 3 Years Ago by pyTony: fixed formating

Attachments
//******************************************************************************
//  Jamie Insalaco
//
//  CIS-165  C++ Programming I
//
//  Last Update:  November 17, 2004
//
//  Description:  Tuition Schedule
//******************************************************************************
//*****************************PRE PROCESSORS***********************************
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
//**********************************MAIN****************************************
int main ()
{
    ofstream outfile;
    
    char    status;
    
    int     credit,
            res_code;
    
    double  cost_per_credit,
            fee,
            tuition,
            tuition_cost;
    
    do{
        cout  <<  "Please enter the number of credits you will take:  ";
        cout  <<  "Credits between 12 and 24 credits only";
        cin   <<  credit;}
    while (credit < 12  ||  credit > 24);        
                            
            
    do{
        cout  <<  "Enter Your Residence Code Number:  ";
        cout  <<  "Code: 1, 2, 3";
        cin   >>  res_code;}
    while!(res_code = 1 || res_code = 2 ||  res_code = 3);
    
    if(res_code = 1){
        cost_per_credit = 45.00;
        status          = "In County";}
    else if(res_code = 2){
        cost_per_credit = 90.00;
        status          = "Out of County";}
    else{
        cost_per_credit = 180.00;
        status          = "Out of State";}
  
    if(credit <= 11)
     fee  =  0.00;
    else
     fee  =  40.00;
     
    tuition  =  cost_per_credit  *  credit;
    tuition_cost  =  tuition + fee;   
              
    cout  <<  "Direct output to the console (1) or to a disk file (2):  ";
    cin   >>  choice;
    if    (choice == 1)
      outfile.open ( "con" );
    else
      outfile.open ( "a:result.dta" );

    outfile  <<  setiosflags (ios::showpoint | ios::fixed) << setprecision (2);
    outfile  <<  setw(47)  <<  "Tuition Schedule"  <<endl;
    outfile  <<  setw(47)  <<  "----------------"  <<endl  <<endl;
    outfile  <<  "Residency Status:  "  <<  status  <<  endl  <<  endl;
    outfile  <<  "Cost per credit:   "  <<  credit  <<  endl  <<  endl;
    outfile  <<  "Credits"  <<  "Fee"  <<  "Tuition"  <<  "Total Cost"  <<  endl;
    outfile  <<  "-------"  <<  "---"  <<  "-------"  <<  "----------"  <<  endl;
    outfile  <<  credit     <<  fee    <<  tuition    <<  tuition_cost  <<  endl;

    outfile.close ( );

}

personally I'd use a switch statement where you use an if statement.
With just a few options it doesn't have significant impact but when things get more complext it greatly enhances readability.

you mean the res_code section? That's not a bad idea. That's not while it won't run, will it?

the part of the problem that gives me the most worry is this:
"write a problem that generates a table showing tuition and fee costs" I guess that means it tops out at 24 credits

This article has been dead for over six months. Start a new discussion instead.