he is what the home work should be. Programming Assignment
CS 320 - Homework Program #1
Due: Sunday, at the end of Week #2
Write a program to compute a student’s tuition for one semester, according to the following specifications.
A student may be classified as undergraduate or graduate. Prompt the user for the student classification and number of units. Error check ALL user input for validity. Re-prompt and allow user corrections for each item when the data is invalid. NOTE: the program should accept either 'U' or 'u' for undergraduate, and either 'G' or 'g' for graduate, and a positive value for the number of units.
Use the following tables to compute the tuition:
Number of Units (UNDERGRADUATE)
Over
But Not Over
Tuition
0
6
$ 500 flat fee + $ 250 per unit
6
12
$ 450 flat fee + $ 245 per unit
12
18
No fee + $ 270 per unit
18
$ 5100 flat feeNumber of Units (GRADUATE)
Over
But Not Over
Tuition
0
6
$ 500 flat fee + $ 250 per unit
6
12
$ 750 flat fee + $ 285 per unit
12
18
No fee + $ 340 per unit
18
$ 6400 flat fee
The program should loop and continue prompting for student classifications and numbers of units until the user indicates s/he is done.
Outputs: Display to the monitor:
Class Undergraduate/Graduate (display word, not letter)
Units xx
Tuition $ xxxxxx.xx
Although the logic for this program is fairly straight-forward, you should allow plenty of time to get used to the C syntax. Only one function, main(), is required in this program. Still, remember to develop and test your code one section at a time.
this is what i have come up with can some one tell me if im on the right track.. I alos fee like I'm doing this the long way.
/*****************************************
File Name: Tmitchellwk1
Description: Calcutaing tuition based on Classification and number of credits
Desinger: Tabatha Mithcell
Date: July 7, 2006
Functions: Input, output
*****************************************/
#include <stdio.h>
main (void)
{
#define flatfeeone 500.00 /*flat rate for up to 6 credits*/
#define Flatfeeu 450.00 /*rate for undergrad rate for 6 to 12
credits*/
#define Flatfeeg 750.00 /*rate for graduate for 6 to 12 credits*/
#define flatunit 250.00 /*rate for fee per credit up to 6 credits*/
#define Flatunitu 245.00 /*rate for undergrate for 6-12 credits*/
#define Flatunitg 285.00 /*rate for graduate for 6-12 credits*/
#define Flatpuu 270.00 /*rate for undgrade for 12-18 credits*/
#define Flatgu 340.00 /*rate for graduate for 12-18 credit*/
#define Flatu 5100.00 /*rate for undgrade for 18 or more credits*/
#define Flatg 6400.00 /*rate for graduate for 18 or more credits*/
int credits; /*number of credits the person is taking*/
char status, /*Student status (G,g-Grad or U,u-Undergrad)*/
data; /*mORE DATA TO ADD*/
float cost; /*amount of tutition*/
printf ("Data\n (y= yes, n = NO)\n\n");
printf ('Do you have more data to add.");
scanf ( "%c", &data);
while ( DATA != N ) {
printf ("Status\n (U = undergraduate, G = Graduate)\n\n");
printf ("Enter status (G/U): ");
scanf ( "%c", &status );
if ( (status == 'g') || (status == 'G') )
{
printf ("Enter number of credits.");
scanf ( "%d", &credits );
if ( (credits >= 0) && (credits <= 6) )
cost = flatfeeone + (credits * flatunit);
if ((credits > 6) && (credits <= 12))
cost = Flatfeeg + (credits *Flatunitg);
if ((credits > 12) && (credits <=18))
cost = Flatgu * credits;
if (credits > 18)
cost = Flatg;
}
else if ((status == 'u') || (status == 'U'))
{
printf ("Enter number of credits.");
scanf ( "%d", &credits );
if ( (credits >= 0) && (credits <= 6))
cost = flatfeeone + (credits * flatunit);
if ( (credits > 6) && (credits <= 12))
cost = Flatfeeu + (credits *Flatunitu);
if ( (credits > 12 ) && (credits <= 18))
cost = Flatpuu * credits;
if (credits > 18)
cost = Flatu;
}
printf ("\nClass %c", status); //fixed output
printf ("\nUnits %d", credits); //fixed output
printf ("\nTuition $%.2f\n", cost); //fixed output
}
return 0;
}