So far is what I've got:

#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>



using namespace std;


int main()
{
	float matric = 47.60;//matriculation fee
	int hrz;//semester hours
	float regroom = 387.29;//rate for regular room
	float acroom = 496.49;//rate for AC room
	float dip = 38.00;//diploma fee
	float food = 619.66;//rate for food
	int stunum;//student ID #
	float credit = 239.33;//cost of each semester hour
	char R;//regular room
	char A;//AC room
	char Y;//Yes
	char N;//No
	

	cout<<"Please enter the student #"<<endl;
	cin>>stunum;
	cout<<stunum<<endl;
	
	cout<<"What are the number of semester hours?"<<endl;
	cin>>hrz;
	if (hrz>21)
	cout<<"You are exceeding 21 semester hours"<<endl;
	else if(hrz<12)
	cout<<"You are taking less than 12 semester hours"<<endl;
	float totalfeez = credit * hrz;//total fee for individual student  
	cout<<totalfeez<<endl;


	cout<<"Please enter your Room Choice: (R/A)"<<endl;
	
	cout<<"Is the student graduating?: (Y/N)"<<endl;


	cout<<food<<endl;
	cout<<matric<<endl;
	cout<<dip<<endl;
	return 0;
}

The assignment:
A local university charges 239.33 for each semester hour of credit., 387.29 per semester for a regular room, 496.49 for an air-conditioned room and 619.66 per semester for food. All students are charged a 47.60 matriculation fee. Graduating students must pay a diploma fee of 38.00.

Write a C++ program that will compute the fees that must be paid by a student. Input from the keyboard will be as follows:

Student # (a four digit #)
Number of semester hours
Room choice('R' for regular, 'A' for air-conditioned)
Graduating ('Y' for yes, 'N' for no)

After all input is typed in, then clear the screen. Output will be as follows:

Student #
A warning message if the student is taking more than 21 hours or less than 12.
Tuition amount
Room: Air conditioned or regular
Food
Matriculation fee
Diploma Fee(if student is graduating).

All help is appreciated....I've having a hard time visualizing how I'd have the options (i.e. Y, N, R, A) being interactive and thus using it to accurately get the student's costs.

Have a good day.

Member Avatar for iamthwee

Plan it out first using a flow chart.
Use doubles instead of floats and don't forget to put brace around your if statements. Although sometimes they're not needed for you it would be beneficial.

#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>



using namespace std;


int main()
{
	float matric = 47.60;//matriculation fee
	int hrz;//semester hours
	string room;//room option
	float regroom = 387.29;//rate for regular room
	float acroom = 496.49;//rate for AC room
	float dip = 38.00;//diploma fee
	string grad//graduation option
	float food = 619.66;//rate for food
	int stunum;//student ID #
	float credit = 239.33;//cost of each semester hour
	char R;//regular room
	char A;//AC room
	char Y;//Yes
	char N;//No
	
	cout<<"Please enter the student #"<<endl;
	cin>>stunum;
		
	cout<<"What are the number of semester hours?"<<endl;
	cin>>hrz;
	if (hrz>21)
	cout<<"You are exceeding 21 semester hours"<<endl;
	else if(hrz<12)
	cout<<"You are taking less than 12 semester hours"<<endl;

	cout<<"Please enter your Room Choice: (R/A)"<<endl;
	cin>>room;
	while (room == 'R')
		cout<<"Regular : "<<regroom<<endl;
	else if (room == 'A')
		cout<<"Air-Conditioned : "<<acroom<<endl;
	
	cout<<"Is the student graduating?: (Y/N)"<<endl;
	cin>>grad;
	while (grad == 'Y')
		cout<<"Diploma fee : "<<dip<<endl;
	else if (grad == 'N')
		cout<<"No graduation this semester"<<endl;
		

	cout<<stunum<<endl;
	float totalfeez = credit * hrz;//total fee for individual student  
	cout<<totalfeez<<endl;
	cout<<"Food : "<<food<<endl;
	cout<<"Matriculation : "<<matric<<endl;
	
	return 0;
}

This is what I kinna thought about..although it doesn't work...but that's kinna my idea as to how it would work....any help would be appreciated.

Member Avatar for iamthwee

Where are your braces?

Surround your if else statement with braces and you probably wanna use double instead of floats.

ok thanks...but my program won't compile...you you like for me to post the errors that i got from the compiler?

Member Avatar for iamthwee

ok thanks...but my program won't compile...you you like for me to post the errors that i got from the compiler?

Of course not, I'd like you to read my advice and follow it though.

Add some braces around the if else while statements. Stick a few couts here and there to see what's going on. Pay attention to your type declarations, strings and chars, etc missing semi-colons, the list could go on...

I'll toss a few more concerns in to the mix in adddition to those already pointed out by iamthwee.

room and grad are declared as string variables but you are trying to compare them to a literal characters when doing things like room == 'R'. Change the declaration of room and grad to type char, not type string and erase the variables called R, A, Y, N as they are just getting you confused.

Also, when you change the declaration of room and grad to type char, then the while loop which matches the user input will go into an infinite loop because there is no way to change the value of room or grad within the while loop. Instead of a while loop, just use an if statement.

Once you get those all working you can add some while loops to help with input validation, control the flow of your program as desired, etc, but until you get the basics down, I wouldn't bother with the while loop stuff.

ok....thx Lerner.....big help...i'll make the necessary changes and repost my new code in a few.Ok guys....thx alot..i got it to work...really appreciate all the assistance..have a good weekend.

My final problem....It compiles ok.....However, for the total cost, i don't see what's not working...I tried the following input: 22 semester hours, air-conditioned room, graduating. The total should be 6467.01 with the matricualtion fee and diploma fee (in this case the student is gaduating)....When i run the program..my total is 6035...My code below:

#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>



using namespace std;


int main()
{
	double matric = 47.60;//matriculation fee
	int hrz;//semester hours
	char room;//room option
	double regroom = 387.29;//rate for regular room
	double acroom = 496.49;//rate for AC room
	double dip = 38.00;//diploma fee
	char grad;//graduation option
	double food = 619.66;//rate for food
	int stunum;//student ID #
	double credit = 239.33;//cost of each semester hour
	
	cout<<"Please enter the student #"<<endl;
	cin>>stunum;
		
	cout<<"What are the number of semester hours?"<<endl;
	cin>>hrz;
		
	cout<<"Please enter your Room Choice: (R/A)"<<endl;
	cin>>room;
	
	cout<<"Is the student graduating?: (Y/N)"<<endl;
	cin>>grad;
		
    cout<<stunum<<endl;
	if (hrz>21)
	{
	cout<<"You are exceeding 21 semester hours"<<endl;
	}
	else if(hrz<12)
	cout<<"You are taking less than 12 semester hours"<<endl;

	double totalfeez = credit * hrz;//total fee for individual student  
	cout<<"Tuition: "<<totalfeez<<endl;

	{
		if (room == 'R')
		cout<<"Room Type : Regular : "<<regroom<<endl;
		else if (room == 'A')
		cout<<"Room Type : Air-Conditioned : "<<acroom<<endl;
	}
	cout<<"Food : "<<food<<endl;
	cout<<"Matriculation : "<<matric<<endl;
	{
		if (grad == 'Y')
		cout<<"Diploma fee : "<<dip<<endl;
		else if (grad == 'N')
		cout<<"No graduation this semester"<<endl;
	}	
	double totalcost = totalfeez + dip + matric + room + food;
	cout<<"Total Fees : "<<totalcost<<endl;
	return 0;
}
Member Avatar for iamthwee

Put a few couts in strategic places to find out where it is going wrong.

ok....so i placed a 'cout' at the end of the statement....so it prints out the room (i.e. A or R) instead of the actual dollar amout...i'll figure it out...thx much.

Member Avatar for iamthwee

Actually the couts won't help, something else is wrong.

Hint: where are you actually assigning the values for the choice entered?

so....in addition to

double regroom = 387.29;
double acroom = 496.49;

, i'm going to have to refer to those values again in the loops?

Member Avatar for iamthwee

Yes what I am saying is here:

{
if (room == 'R')
cout<<"Room Type : Regular : "<<regroom<<endl;
else if (room == 'A')
cout<<"Room Type : Air-Conditioned : "<<acroom<<endl;
}

How does it know that room is now equal to acroom?

Where have you said room = acroom in your code?

ok...thx much..i see it...i had thought that when the user enters (A) which stands for acroom(air-conditioned room) it would automatically put the value of acroom in room adn thus carry out the calculation.

Member Avatar for iamthwee

There is no such thing as automatically in programming, computers can't read your mind.

ok..got it now....really appreciate it..it's working perfect now...have another assignment to post on wednesday...c u then...

i guess the same would apply for the room option doesn't work....if i choose 'R' for room option...it prints out the letter...rather than the cost (but it does the calculation ok)...

it works for air-conditioned room....but not for regular room

When you want help with your code after making changes, it's customary to post the latest version. Otherwise it's extremely difficult to help you effectively.

#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>



using namespace std;


int main()
{
	double matric = 47.60;//matriculation fee
	int hrz;//semester hours
	char room;//room option
	double regroom = 387.29;//rate for regular room
	double acroom = 496.49;//rate for AC room
	double dip = 38.00;//diploma fee
	char grad;//graduation option
	double food = 619.66;//rate for food
	int stunum;//student ID #
	double credit = 239.33;//cost of each semester hour
	double totalcost;//student's total cost per semester
	
	cout<<"Please enter the student #"<<endl;
	cin>>stunum;
		
	cout<<"What are the number of semester hours?"<<endl;
	cin>>hrz;
		
	cout<<"Please enter your Room Choice: (R/A)"<<endl;
	cin>>room;
	
	cout<<"Is the student graduating?: (Y/N)"<<endl;
	cin>>grad;
		
    cout<<stunum<<endl;
	if (hrz>21)
	{
	cout<<"You are exceeding 21 semester hours"<<endl;
	}
	else if(hrz<12)
	cout<<"You are taking less than 12 semester hours"<<endl;

	double totalfeez = credit * hrz;//total fee for individual student  
	cout<<"Tuition: "<<totalfeez<<endl;

	{
		if (room == 'R')
		cout<<"Room Type : Regular : "<<regroom<<endl;
		else if (room == 'A')
		cout<<"Room Type : Air-Conditioned : "<<acroom<<endl;
	}
	cout<<"Food : "<<food<<endl;
	cout<<showpoint<<setprecision(4)<<"Matriculation : "<<matric<<endl;
	{
		if (grad = 'Y')
		cout<<"Diploma fee : "<<dip<<endl;
		else if (grad = 'N')
		cout<<endl;
	}
	{
		if (room = acroom)
		totalcost = totalfeez + dip + matric + acroom + food;
		else if (room = regroom)
		totalcost = totalfeez + dip + matric + regroom + food;
	}
		cout<<setprecision(6)<<"Total Fees : "<<totalcost<<endl;
	

	return 0;
}

A few problems: if i select 'N' for the graduation option...it still includes 'dip' into the total fees...The option, when I select 'R' for regular room...it doesn't 'cout' after it's compiled.

All of the {}s done like this:

{
   if (room == 'R')
   cout<<"Room Type : 
   else if (room == 'A')
   cout<<"Room Type : 
}

are worthless. They don't do anything. It should be like this

if (room == 'R')
{
   cout<<"Room Type : 
}
else if (room == 'A')
{
    cout<<"Room Type : Air-
}

or some other {} style, so that each set of {}s is enclosing a block of statements after each if and each else if, etc. You should also be indenting the block of statements within the {}s so it's easier to tell if you mismatch them.

When you calculate totalcost you always add dip to it. You have to do something to avoid hardwiring the value of dip into totalcost. Options I see off hand are to:
1) use an conditional statement to determine if you need to add dip to totalcost or not, or
2) make totalcost a running total (easy to do if you know about the += operator)

I did change the braces for the room options....still didn't work.....it didn't 'cout' the option for air-conditioned room....

rather....it didn't work when i chose regular room

Ok guys...nice job...thx 4 all the help....i figured it out....

Member Avatar for iamthwee

Ok guys...nice job...thx 4 all the help....i figured it out....

Please can you post your 'finished' solution for the benefit of the daniweb community and so that others can check over it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.