Can someone help please? I'm looking at the program and can't seem to find where I went wrong.

Write your question here.
I am writing a project that calculates and prints the semester college bill for a college. The college has two types of students : undergraduate and graduate. Tuition varies depending on the type of student, state residency and whether a student is full or part-time and I have to should prompt the user to enter student ID number, a level code (‘U’ for undergraduate or ‘G’ for graduate), state resident code (‘Y’ or ‘N’) and whether the student is full or part time code (‘F’ or ‘P’).
Also,
• If any of the entered codes are not one of those specified, it should be treated as an error
• If a student is part-time, the user needs to be prompted for number of credit hours.
For graduate students only, the student may be enrolled in the special Biology program, which has an additional fee of $900 per semester.. Therefore, to calculate a graduate student’s bill, you must ask the user if the student is in the Biology program
with two value returning functions.


#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main(int argc, char** argv) {

char StudentID, Studentlevel, ResidentCode, Pt_Ft, Biology;
double Total_bill, Tuition_per_semester, Fees_per_semester;
double Tuition_per_credit_hour, Fees_per_credit_hour, Biology_Fee;
int CreditHours;

/* UndergraduateBill : This function calculates and returns the billing amount for an
Undergraduate student.
*/


int main () {
int StudentID, char Studentlevel, char ResidentCode, char Pt_Ft, int CreditHours, char Biology
cout<< fixed<< setprecision(2)<<endl;

cout<< "Enter your student ID number"<<;
cin>> StudentID;
cout<< "What level student are you? (U for 'Undergrad' and G for 'Graduate')"<<;
cin>> Studentlevel;
if (Studentlevel != 'U' or 'G')
{
cout<< "Error: Invalid"<<;
break;
}

cout<< "Are you an In-State student ? ('Y' for In-State and 'N' for Out-Of-State)"<<;
cin>> ResidentCode
if (ResidentCode != 'Y' or 'N')
{
cout<< "Error: Invalid"<<;
break;

}
cout<< "Are you part time or full time? ('P' for Part time and 'F' for 'full time'"<<;
cin>> Pt_Ft;
if (Pt_Ft != 'P' or 'F')
{
cout<< "Error: Invalid"<<;
break;

if (Pt_Ft == 'P')

cout<< "Enter the total credit hours in which you are enrolled"<<;
cin CreditHours;
}

if (Studentlevel == 'G')
{
cout<< "Would you like to enroll in the Special Biology Program? ('Y' or 'N')"<<;
cin>> Biology;
}
cout<< "Student Account:"<< StudentID<< endl;
cout<< "/n Bill Amount:"<< Total_bill<< endl;

}

char Undergraduate (char ResidentCode, char Pt_Ft, int CreditHours);
{
if (Studentlevel == 'U' && Pt_Ft >= 12)
{
if (ResidentCode == 'Y')

Tuition_per_semester= 3085;
Fees_per_semester= 588.50;

if (ResidentCode == 'N')
Tuition_per_semester= 7910;
Fees_per_semester= 588.50;

Total_bill= Tuition_per_semester + Fees_per_semester;
return Total_bill;
}
if (Studentlevel == 'U' && Pt_Ft < 12)
{
if (ResidentCode == 'Y')
Tuition_per_credit_hour= 257 * CreditHours;
Fees_per_credit_hour= 48.95 * CreditHours;

if (ResidentCode == 'N')
Tuition_per_credit_hour= 659 * CreditHours;
Fees_per_credit_hour= 48.95 * CreditHours;
Total_bill= Tuition_per_credit_hour + Fees_per_credit_hour;

return Total_bill;
}
}

char Graduate (char ResidentCode,char Pt_Ft,char Biology,int CreditHours);
{

if (Studentlevel == 'G' && Pt_Ft >= 12)
{
if (ResidentCode == 'Y')
Tuition_per_semester= 5185;
Fees_per_semester= 342.14;

if (ResidentCode == 'N')
Tuition_per_semester= 10095;
Fees_per_semester= 342.14;
}
if (Biology == 'Y')
{
Biology_Fee= 900;

if (Biology == 'N')
Biology_Fee= 0;

Total_bill= Tuition_per_semester + Fees_per_semester+ Biology_Fee;

return Total_bill;
}
}


char Graduate (char ResidentCode, char Pt_Ft,char Biology,int CreditHours)
{
if (Studentlevel == 'G' && Pt_ft < 12)
{
if (ResidentCode == 'Y')

Tuition_per_credit_hour= 432 * CreditHours;
Fees_per_credit_hour= 28.37 * CreditHours;

if (ResidentCode == 'N')
Tuition_per_credit_hour= 841 * CreditHours;
Fees_per_credit_hour= 28.37 * CreditHours;
}
if (Biology == 'Y')
{
Biology_Fee= 900;

if (Biology_Program == 'N')
Biology_Fee= 0;

Total_bill= Tuition_per_credit_hour + Fees_per_credit_hour+ Biology_Fee;

return Total_bill;
}
}


return 0;
}
// also, every time I compile it says ""A function definition is nor allowed here before '{'""
Last edited on
Next time please post your code within the code blocks (under Format). You have declared main() twice. This is not the correct way to code an "if" statement:

if (Studentlevel != 'U' or 'G')

It should be more like this:

1
2
if( StudentLevel != 'Y' || StudentLevel != 'G' )
Okay, next time I will. And I tried to deleted the first main and it shows me a WHOLE bunch of errors so I put it back in. And thanks :)
You've got a main function... inside another main function? WTF?

I don't think you've understood what a function is. Before you keep banging away at this, you should go back to your learning materials and learn what a function is.
Last edited on
I do not, I repeat I don't know or understand functions so before you get rude, fix your attitude, please.
You cannot, I repeat, cannot code in C++ without using functions. Do you want sugar-coated special snowflakes, or do you want to write code that will work?

While I'm here, if this is for some kind of graded assignment, leaving your name in it isn't a great idea. A google search of your name and C++ returns this thread as the first hit.
Last edited on
so I put it back in.
As stated by koothkeeper, you can't have nested implementations of main.

line 22:
int StudentID, char Studentlevel, char ResidentCode, char Pt_Ft, int CreditHours, char Biology
You can't mix type declarations of different type in the same statement.
Should be:
1
2
3
4
5
6
int StudentID;  // Note the ;
char Studentlevel;  // ; required
char ResidentCode;  // ; required
char Pt_Ft;  //  ; required 
int CreditHours;  // ; required
char Biology;  // ; required 


line 25,27,31,35,39,43,47,52,58:
cout<< "Enter your student ID number"<<; // extraneous << operator

line 29,37,45: 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 32,40,48: break is illegal here.

line 36: missing ;

line 51: missing {

line 53: missing the >> operator.

line 66: Function Undergraduate is never called. The ; makes this a function declaration, not a function.

Line 97: Ditto for function graduate.

lines 72-73: You probably want {} around these statements.

line 80,93,115: You're trying to return a double from a function that is type char.

Line 124: You have duplicate functions named Graduate.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Last edited on
Thank you so much! :)
@AbstractionAnon I tried clicking the <> button but it does nothing.
You have to highlight your code.
I did.
Your code with code tags:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main(int argc, char** argv) {

char StudentID, Studentlevel, ResidentCode, Pt_Ft, Biology;
double Total_bill, Tuition_per_semester, Fees_per_semester;
double Tuition_per_credit_hour, Fees_per_credit_hour, Biology_Fee;
int CreditHours;

/* UndergraduateBill : This function calculates and returns the billing amount for an
Undergraduate student.
*/


int main () {
int StudentID, char Studentlevel, char ResidentCode, char Pt_Ft, int CreditHours, char Biology
cout<< fixed<< setprecision(2)<<endl;

cout<< "Enter your student ID number"<<;
cin>> StudentID;
cout<< "What level student are you? (U for 'Undergrad' and G for 'Graduate')"<<;
cin>> Studentlevel;
if (Studentlevel != 'U' or 'G')
{
cout<< "Error: Invalid"<<;
break;
}

cout<< "Are you an In-State student ? ('Y' for In-State and 'N' for Out-Of-State)"<<;
cin>> ResidentCode
if (ResidentCode != 'Y' or 'N')
{
cout<< "Error: Invalid"<<;
break;

}
cout<< "Are you part time or full time? ('P' for Part time and 'F' for 'full time'"<<;
cin>> Pt_Ft;
if (Pt_Ft != 'P' or 'F')
{
cout<< "Error: Invalid"<<;
break;

if (Pt_Ft == 'P')

cout<< "Enter the total credit hours in which you are enrolled"<<;
cin CreditHours;
}

if (Studentlevel == 'G')
{
cout<< "Would you like to enroll in the Special Biology Program? ('Y' or 'N')"<<;
cin>> Biology;
}
cout<< "Student Account:"<< StudentID<< endl;
cout<< "/n Bill Amount:"<< Total_bill<< endl;

}

char Undergraduate (char ResidentCode, char Pt_Ft, int CreditHours);
{
if (Studentlevel == 'U' && Pt_Ft >= 12)
{
if (ResidentCode == 'Y')

Tuition_per_semester= 3085;
Fees_per_semester= 588.50;

if (ResidentCode == 'N')
Tuition_per_semester= 7910;
Fees_per_semester= 588.50;

Total_bill= Tuition_per_semester + Fees_per_semester;
return Total_bill;
}
if (Studentlevel == 'U' && Pt_Ft < 12)
{
if (ResidentCode == 'Y')
Tuition_per_credit_hour= 257 * CreditHours;
Fees_per_credit_hour= 48.95 * CreditHours;

if (ResidentCode == 'N')
Tuition_per_credit_hour= 659 * CreditHours;
Fees_per_credit_hour= 48.95 * CreditHours;
Total_bill= Tuition_per_credit_hour + Fees_per_credit_hour;

return Total_bill;
}
}

char Graduate (char ResidentCode,char Pt_Ft,char Biology,int CreditHours);
{

if (Studentlevel == 'G' && Pt_Ft >= 12)
{
if (ResidentCode == 'Y')
Tuition_per_semester= 5185;
Fees_per_semester= 342.14;

if (ResidentCode == 'N')
Tuition_per_semester= 10095;
Fees_per_semester= 342.14;
}
if (Biology == 'Y')
{
Biology_Fee= 900;

if (Biology == 'N')
Biology_Fee= 0;

Total_bill= Tuition_per_semester + Fees_per_semester+ Biology_Fee;

return Total_bill;
}
}


char Graduate (char ResidentCode, char Pt_Ft,char Biology,int CreditHours)
{
if (Studentlevel == 'G' && Pt_ft < 12)
{
if (ResidentCode == 'Y')

Tuition_per_credit_hour= 432 * CreditHours;
Fees_per_credit_hour= 28.37 * CreditHours;

if (ResidentCode == 'N')
Tuition_per_credit_hour= 841 * CreditHours;
Fees_per_credit_hour= 28.37 * CreditHours;
}
if (Biology == 'Y')
{
Biology_Fee= 900;

if (Biology_Program == 'N')
Biology_Fee= 0;

Total_bill= Tuition_per_credit_hour + Fees_per_credit_hour+ Biology_Fee;

return Total_bill;
}
}


return 0;
}
// also, every time I compile it says ""A function definition is nor allowed here before '{'"" 
Last edited on
thanks!
Topic archived. No new replies allowed.