// Name: cs157a5wrong.c // Purpose: Developing test cases to catch program errors // // errors purposely added // // Author: Dr. Michael A. Redmond // Date Written: // NOTES: // #include // Define constants const double in_town_high_rate = 500; const double in_town_low_rate = 200; const double out_town_high_rate = 1000; const double out_town_low_rate = 400; const int low_cred_cutoff = 12; const int max_poss_cred = 21; const double disc_adj = 0.80; int main() { // Declarations int credits; double cost, high_rate, low_rate; char resid, disc, check_char; // int invalid_std; // bool invalid_std; // _bool; // read input printf("Please enter student's residency (I - intown or O -out of town): "); scanf("%c",&resid); scanf("%c",&check_char); // check residency status while ( (resid != 'I') && (resid != 'O') ) { printf("invalid residence: %c \n",resid); printf("Please enter student's residency (I - intown or O -out of town): "); scanf("%c",&resid); scanf("%c",&check_char); } printf("Please enter student's discount status (D - discounted or N - not discounted): "); scanf("%c",&disc); scanf("%c",&check_char); // check discount status if ( (disc != 'D') && (disc != 'N') ) { printf("invalid discount: %c \n",disc); printf("Please enter student's discount status (D - discounted or N - not discounted): "); scanf("%c",&disc); scanf("%c",&check_char); } printf("Please enter student's number of credits (1-21): "); scanf("%d",&credits); // check number of credits while ( (credits <= 1) || (credits > max_poss_cred) ) { printf("invalid credits: %2d \n",credits); printf("Please enter student's number of credits (1-21): "); scanf("%d",&credits); } // debugging - echo check printf("echo: | %c | | %c | | %2d | \n",resid,disc,credits); //////////////////////////////////////////////////////////////////////////// // HERE - based on residency and discount status - determine rates - these are // then used later in tuition calculation //////////////////////////////////////////////////////////////////////////// // divide based on residence in-town or out-of-town if (resid == 'I') { // in-town - now determine if discounted or not if (disc == 'N') { // not discounted printf("In town regular \n"); high_rate = in_town_high_rate; low_rate = in_town_low_rate; } else { // discounted printf("In town discounted \n"); high_rate = in_town_high_rate * disc_adj; low_rate = in_town_high_rate * disc_adj; } } // end resid in town // otherwise should be out of town - but make sure else if (resid == 'O') { // out of town - now determine if discounted or not if (disc == 'N') { // not discounted printf("Out of town regular \n"); high_rate = out_town_high_rate; low_rate = out_town_low_rate; } else { // discounted printf("Out of town discounted \n"); high_rate = out_town_high_rate * disc_adj; low_rate = out_town_low_rate * disc_adj; } } // end residence out of town //////////////////////////////////////////////////////////////////////////// // NOW - based on #credits and tuition rates determined above - calculate tuition //////////////////////////////////////////////////////////////////////////// // see if all credits are charged at the higher rates if ( credits < low_cred_cutoff ) { cost = credits * high_rate; } // see if credits are charged at mixed rates if ( credits > low_cred_cutoff) { // first credits (12) are charged at higher rate, then rest at lower rate cost = (low_cred_cutoff * high_rate) + ((credits - low_cred_cutoff) * low_rate); } // write out header to table here printf("Residency Discount Credits Tuition \n"); printf("--------- -------- ------- ------- \n"); // write out student info printf(" %c %c %2d %7.2f \n",resid,disc,credits,cost); return 0; } // end main