Write a program to calculate semester fees that must be paid by a student at a State university using the following values:
Each semester unit $90.00
Regular room charge $200.00
Air conditioned room $250.00
Food charge $400.00
Matriculation fee (all students) $30.00
Diploma fee (if graduating student) $35.00
Input student ID number (one integer containing four digits), the type of a room (regular or air conditioned as one letter R/A), number of units, and whether or not the student is graduating (Y/N). Output an itemized list of student fees and a total of the student fee owed. Check for students taking more than 21 units and students taking fewer than 12 units. Output a message to students enrolled in more than 21 units (this is not allowed, do NOT process this data) or fewer than 12 units (warn them that they are not full time students but DO process this data).
Input
Student identification number, type of room (R, A), number of units, and whether or not student is graduating (Y/N). If there is an error in input (units, type of room, number of units, graduating or not) output all student data and a specific error message and do NOT process any student record that contains any error data.
This is not a homework site. We won't do your homework for you. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.
What help is needed? Have you produced a program design? Do you understand how this would be done using pen/paper? What are the instructions you would give to someone else to do this who didn't know the requirements?
Once you have the design, then you can start coding. Code in small parts and compile and test frequently. Don't try to write the whole program at once then compile and find there are many compile errors.
What C++ issue are you having problems with? Can you display text, obtain values etc? Post your current code.
cout << "Please enter number of units " ;
cin >> Units;
if (Units < unit_min || Units > unit_max )
{
cout <<" Unit can not be more than 21 or less than 1 " << endl;
cout <<" Please enter the valid number " << endl;
}
Unitprice = UNIT * Units;
cout << "Please enter your four digits student ID " ;
cin >> StudentID;
cout << "Please enter R for regular room or A for AC Room " ;
cin >> RoomType;
if (RoomType == 'R' || 'r')
{
Roomprice = RoomType * RROOM;
RoomName = "Regular";
}
else if (RoomType == 'A' || 'a')
{
Roomprice = RoomType * ACROOM;
RoomName = "AirCondtion";
}
cout << " Are you Graduating (Y or r) for yes and (N or n) for no " ;
cin >> Graduating;
while (!(letter == 'y') || (letter == 'Y') || (letter == 'n') || (letter == 'N'))
cout << "Error: You must enter Y for yes N for no" ;
George, I'm glad you and others take the time to tell newbies how to format their code, but I think the use of all-caps in the 'PLEASE' part of your quoted message immediately discourages people from reading it, because it gives off the vibe that you're yelling at them. What's in it for them? Also, the double-spacing between each short sentence makes it overall harder to digest.
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
constfloat UNIT = 90.00;
constfloat RROOM = 200.00;
constfloat ACROOM = 250.00;
constfloat FOOD = 400.00;
constfloat MATRI = 30.00;
constfloat DIPLOM = 35.00;
constint N = 10;
constint unit_min = 1;
constint unit_max = 21;
char letter = 'y';
int main() {
float Unitprice, Roomprice, Foodprice, Martriculationprice, Total;
int Units, StudentID;
char RoomType, Graduating, letter;
string RoomName;
cout << "Please enter number of units ";
cin >> Units;
if (Units < unit_min || Units > unit_max) {
cout << " Unit can not be more than 21 or less than 1 " << endl;
cout << " Please enter the valid number " << endl;
}
Unitprice = UNIT * Units;
cout << "Please enter your four digits student ID ";
cin >> StudentID;
cout << "Please enter R for regular room or A for AC Room ";
cin >> RoomType;
if (RoomType == 'R' || 'r') {
Roomprice = RoomType * RROOM;
RoomName = "Regular";
} elseif (RoomType == 'A' || 'a') {
Roomprice = RoomType * ACROOM;
RoomName = "AirCondtion";
}
cout << " Are you Graduating (Y or r) for yes and (N or n) for no ";
cin >> Graduating;
while (!(letter == 'y') || (letter == 'Y') || (letter == 'n') || (letter == 'N'))
cout << "Error: You must enter Y for yes N for no";
Total = Unitprice + Roomprice + FOOD + MATRI + DIPLOM;
cout << fixed << showpoint << setprecision(2) << endl;
cout << "Prie of the Units $" << setw(N) << Unitprice << endl;
cout << "Food Charge $" << setw(N) << FOOD << endl;
cout << "AC Room price $" << setw(N) << ACROOM << endl;
cout << "Matricuation $" << setw(N) << MATRI << endl;
cout << "Total Semester Charge $" << setw(N) << Total << endl;
}
As a starter:
L39/42 don't do what you think they do. See L26
L15/L20. letter is defined in both. L15 will be ignored.
L48 Input is to Graduating - but you test letter in the condition L50
L50 If letter is not a y or n then you'll get an infinite loop of messages as letter isn't changed in the loop
Lines 26-29: If the number of units is out of range, you output a message and then keep going as if nothing was wrong. Your instructions specifically state
do NOT process any student record that contains any error data.
Line 26: You have not checked for less than 12 units.
fewer than 12 units (warn them that they are not full time students but DO process this data)
Lines 39,42: C++ does not support implied left hand side in conditionals. You must fully specify the conditions.
Example: if (ans == 'Y' || 'y') evaluates as if ((ans == 'Y') || ('y'))
('y') always evaluates to 1 (true), therefore the if statement is always true.
Line 50: The ! negates only the first condition. You need parenthesis around all the conditions.