| | |
do while; if else? am I using the right code for the problem?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2004
Posts: 21
Reputation:
Solved Threads: 0
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 ( );
}
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 ( );
}
![]() |
Similar Threads
- Email code problem (PHP)
- Code Problem (Modifying Book Code to adapt to program) (Java)
- login code problem (VB.NET)
- can anyone help me with this progam,and write the code for this problem? (C)
- Code problem with an array displaying list (C#)
- Problem with a snippet of code in a shell program (C)
- DrawHouse Code Problem (Java)
Other Threads in the C++ Forum
- Previous Thread: How to be Crash Free
- Next Thread: Dealing w/ virtual functions
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






