954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

do while; if else? am I using the right code for the problem?

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
#include
#include
//**********************************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" <

Attachments tuition_schedule.cpp (2.49KB)
jamievmi2
Newbie Poster
21 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

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.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

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

jamievmi2
Newbie Poster
21 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You