If-else loop help

Hi, I am developing a program with the following criteria:

Your program must accept as input the school the student is applying to (L or M), their high school grade point average, their math SAT score, their verbal SAT score and whether or not either parent is an alumnus (Y or N). The program must process several applicants, echoing the data for each applicant and printing a message indicating if the student was accepted to the school they were applying to. If they were not accepted, the message should indicate why. This message only has to indicate one reason for failure in cases of multiple disqualifications. Acceptances are to be made in the order received so that if a school is full, a later applicant cannot be accepted even if they happen to have better qualifications than an earlier one. You do NOT have to check for bad data coming from the file – assume that it is in the required format and has appropriate values.

The data file is arranged with the information for each applicant on a separate line. Your program must process the data until the end of file is reached, at which time the program must print out the total number of applicants and the number of acceptances to each school. The data file has been created for you and is located on the network mp3accept.txt.

Now my code looks fine but I think the main problem is that my data is not reinitializing and it holds onto the true values until it comes across a false value (pardon my nooby language). My code is as follows:

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

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
	char school = ' ', alumni = ' ';
	double gpa = 0.0;
	int mSAT = 0, vSAT = 0;
	int acceptedmusic = 0;
	int acceptedliberal = 0;

	ifstream fin; //defining command name

	fin.open("C:\\MP3accept.txt");

    while (fin.good())
    {
      fin >> school >> gpa >> mSAT >> vSAT >> alumni;
	if (school = 'L') //school of liberal arts
	{ cout << "School = " << school;
		if (alumni = 'Y') // check if parent is an alumni or not
			{if ( gpa >= 3.0 && mSAT + vSAT >= 1000) // check to see if minimum is met
		{cout << "GPA = " << gpa << "math SAT = " << mSAT
			<< "verbal SAT = " << vSAT << "Parent's alumni status = " << alumni << endl
			<< "Applying to Liberal Arts" << endl
			<< "Accepted to Liveral Arts!" << endl;}
			
			else ( gpa < 3.0 || mSAT + vSAT < 1000); // minimum requirement is not met
			{ if (gpa < 3.0) // gpa is the first thing that is looked at. doesn't matter if SAT is low as well
		{cout << " GPA = " << gpa << " math SAT = " << mSAT
			<< " verbal SAT = " << vSAT << " Parent's alumni status = " << alumni << endl
			<< "Applying to Liberal Arts" << endl
			<< "Rejected - GPA requirement not met" << endl;}
			else (mSAT + vSAT < 1000);
			{ cout << "School = " << school << " GPA = " << gpa << " math SAT = " << mSAT
			<< " verbal SAT = " << vSAT << " Parent's alumni status = " << alumni << endl
			<< "Applying to Liberal Arts" << endl
			<< "Rejected - SAT scores are not high enough" << endl;}}
		}

		else(alumni = 'N'); 
		{if( gpa >= 3.5 && mSAT + vSAT >= 1200) // check to see if minimum is met
		{cout << " GPA = " << gpa << " math SAT = " << mSAT
			<< " verbal SAT = " << vSAT << " Parent's alumni status = " << alumni << endl
			<< "Applying to Liberal Arts" << endl
			<< "Accepted to Liveral Arts!" << endl;}
			
			else (gpa > 3.5 || mSAT + vSAT > 1200); // minimum requirement is not met
			{ if (gpa < 3.5) // gpa is the first thing that is looked at. doesn't matter if SAT is low as well
		{cout << " GPA = " << gpa << " math SAT = " << mSAT
			<< " verbal SAT = " << vSAT << " Parent's alumni status = " << alumni << endl
			<< "Applying to Liberal Arts" << endl
			<< "Rejected - GPA requirement not met" << endl;}
			else (mSAT + vSAT < 1200);
			{ cout << " GPA = " << gpa << " math SAT = " << mSAT
			<< " verbal SAT = " << vSAT << " Parent's alumni status = " << alumni << endl
			<< "Applying to Liberal Arts" << endl
			<< "Rejected - SAT scores are not high enough" << endl;}}
		}}
	
	else (school = 'M') ; //school of music
	{ cout << "School = " << school; 
		if(mSAT >= 500 && vSAT >= 500)
			{cout << " GPA = " << gpa << " math SAT = " << mSAT
			<< " verbal SAT = " << vSAT << " Parent's alumni status = " << alumni << endl
			<< "Applying to Music" << endl
			<< "Accepted to Music" << endl;}
	else(mSAT < 500 || vSAT < 500);
	{ cout << " GPA = " << gpa << " math SAT = " << mSAT
			<< " verbal SAT = " << vSAT << " Parent's alumni status = " << alumni << endl
			<< "Applying to Music" << endl
			<< "Rejected - SAT scores are not high enough" << endl;}
	}
	
	
	
	
	
  
  }


  fin.close();





  system("pause");


return 0;
	
}
I just need help on how to reinitialize my values.
"=" is initializer
"==" is read as "is equal with"

if you want to use a condition on else, use else if
Last edited on
1
2
// if (school = 'L') // **** = is the assignment operator, it assigns the value 'L' to school 
if (school == 'L')  // == compares for equivalence - is the value in 'school' equal to 'L'? 

And likewise in your other if statements.


Oh, and change this
1
2
3
4
while (fin.good())
    {
      fin >> school >> gpa >> mSAT >> vSAT >> alumni;
      // ... 

to
1
2
3
while( fin >> school >> gpa >> mSAT >> vSAT >> alumni )
    {
        // ... 

Last edited on
Also, you can't just use else. It's else if(..) and NO semi-colon afterwards. The semi-colon terminates the statement.
I should have probably mentioned that parents being an alumni has an effect on the criteria. If the parent is an alumni, they get accepted at lower scores vs. the standard scores they get accepted as if their parents were not alumni.
Thank you guys for all the advice and pointers. I have finished the program and it works great. All of you were awesome!
Topic archived. No new replies allowed.