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

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2004
Posts: 21
Reputation: jamievmi2 is an unknown quantity at this point 
Solved Threads: 0
jamievmi2 jamievmi2 is offline Offline
Newbie Poster

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

 
0
  #1
Nov 20th, 2004
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, 4 views)
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

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

 
0
  #2
Nov 20th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 21
Reputation: jamievmi2 is an unknown quantity at this point 
Solved Threads: 0
jamievmi2 jamievmi2 is offline Offline
Newbie Poster

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

 
0
  #3
Nov 20th, 2004
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC