Help me with nested if else statements and attaching files, the attached text fi
ID: 3871773 • 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
#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
#include<stdio.h>
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;
infile >> gpa;
infile >> math;
infile >> verbal;
infile >> alumna;
cout << "School = "<<school;
cout << "GPA = "<<gpa;
cout << "math = "<<math;
cout << "verbal = "<<verbal;
cout << "alumna= "<<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;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.