Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help me with nested if else statements and attaching files, the attached text fi

ID: 3871956 • Letter: H

Question

Help me with nested if else statements and attaching files, the attached text file isn't input into the variables I set. Please explain everything as well, Im in an intro to c++ class. Can you please make sure it works before submitting this answer? This is my second time posting since someone who answered the first one didn't even change a thing about my code.

#include

#include

using namespace std;

int main (void)

{

fstream infile;

infile.open("mp3accept.txt");

char school, alumna;

float gpa;

int math, verbal;

cout << "Acceptance to your college by John Doe ";

   while(! infile.eof()){

infile >> school;

  

cin >> gpa;

  

cin >> math;

  

cin >> verbal;

  

cin >> alumna;

   cout << "School = "<

   cout << "GPA = "<

   cout << "math = "<

   cout << "verbal = "<

   cout << "alumna= "<

if((school == 'L') && (alumna == 'Y')){

cout << "Applying to Liberal Arts!!! ";

if (gpa >= 3.0)

{

if ((verbal + math) >= 1000)

{

cout << "Congrats you are accepted! Alumna queen";

}

  

else{

cout << "Rejected - SAT too low";

}

}

else

{

cout << "Rejected - GPA too low";

}

}

else if ((school == 'L') && (alumna == 'N')) {

cout << "Applying to Liberal Arts!!! ";

if (gpa >= 3.5)

{

if ((verbal + math) >= 1200)

{

cout << "Congrats you are accepted! Normie";

  

}

else

{

cout << "Rejected - SAT too low";}

}

else

{

cout << "Rejected - GPA too low";}

}

else if (school == 'M')

{

cout << "Applying to Music!! ";

if ((verbal + math) >= 1000)

{

cout << "Congrats you are accepted! ";}

else

{

cout << "Rejected - SAT too low ";}

}

cout<<"******************************* ";

}

  

  

return 0;

}

here is the text file I'm using:

L 3.4 600 600 N

L 3.0 500 490 Y

L 2.9 500 500 Y

Here's how it should look

Applicant #: 1
School = L GPA = 4.0 math = 600 verbal = 650 alumnus = N
Applying to Liberal Arts
Accepted to Liberal Arts!!!
*******************************
Applicant #: 2
School = M GPA = 3.9 math = 610 verbal = 520 alumnus = N
Applying to Music
Accepted to Music!!
*******************************
Applicant #: 3
School = L GPA = 3.8 math = 590 verbal = 600 alumnus = N
Applying to Liberal Arts
Rejected - SAT is too low
*******************************

Explanation / Answer

hi, In the given program has been changed with else if ladder.

//accepts the input from the file and displays the message

using namespace std;

int main (void)

{

fstream infile;
//opens the text file
infile.open("mp3accept.txt");
// declare the variables for accepting values from the file
char school, alumna;
float gpa;
int math, verbal;
//displays message
cout << "Acceptance to your college by John Doe ";
//performs the loop until the end of file
while (!infile.eof()) {
  
//accepts the input from the file
infile>>school;
infile>>gpa;
infile>>math;
infile>>verbal;
infile>>alumna;
  
//displays the accepted information in the std output
cout << " School = " << school;
cout << " GPA = " << gpa;
cout << " math = " << math;
cout << " verbal = " << verbal;
cout << " alumna= " << alumna;
  
//condition checking using nested if..else if ladder
if ((school = 'L') && (alumna = 'Y')) {
cout << " Applying to Liberal Arts!!! ";
if ((gpa >= 3.0)&&((verbal + math) >= 1000)) {
cout << " Congrats you are accepted! Alumna queen";
} else if ((gpa >= 3.0)&&((verbal + math) < 1000)) {
cout << " Rejected - SAT too low";
} else {
cout << " Rejected - GPA too low";
}
} else if ((school = 'L') && (alumna = 'N')) {
cout << " Applying to Liberal Arts!!! ";
if ((gpa >= 3.5)&& ((verbal + math) >= 1200)) {

cout << " Congrats you are accepted! Normie";

} else if ((gpa >= 3.5)&& ((verbal + math) < 1200)) {
cout << " Rejected - SAT too low";
} else {
cout << " Rejected - GPA too low";
}
} else if (school == 'M') {
cout << " Applying to Music!! ";
if ((verbal + math) >= 1000) {
cout << " Congrats you are accepted! ";
} else {
cout << " Rejected - SAT too low ";
}
}
cout << " ******************************* ";
}

return 0;
}