944,028 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5112
  • C++ RSS
Nov 20th, 2004
0

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

Expand Post »
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 ( );

}
Attached Files
File Type: cpp tuition schedule.cpp (2.5 KB, 9 views)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jamievmi2 is offline Offline
21 posts
since Nov 2004
Nov 20th, 2004
0

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

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Nov 20th, 2004
0

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

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jamievmi2 is offline Offline
21 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: How to be Crash Free
Next Thread in C++ Forum Timeline: Dealing w/ virtual functions





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC