Question
c++ if I choose gradYear = 2019 and currentYear = 2015, the below program doesnt work out well; it works fine for other conditions... #include
c++
if I choose gradYear = 2019 and currentYear = 2015, the below program doesnt work out well; it works fine for other conditions...
#include
using namespace std;
int main()
{
string name, status;
int gradYear, currentYear, difference, gradCurrent;
// User I/O
cout << "Please enter your name: ";
cin >> name;
cout << "Please enter your graduation year: ";
cin >> gradYear;
cout << "Please enter current year: ";
cin >> currentYear;
// Define status to output whether graduated/not/college year
gradCurrent = (currentYear + 4);
if (gradYear == currentYear) {
cout << " " << name << ", your status: graduated" << endl;}
else if (gradYear >= gradCurrent){
cout << " " << name << ", your status: not in college yet" << endl;}
else if (gradYear < currentYear) // Displays "graduated"
cout << " " << name << ", your status: graduated" << endl;
else if (gradYear > currentYear) // calculates college level
{
difference = gradYear - currentYear;
if (difference == 1)
status = "senior";
else if (difference == 2)
status = "junior";
else if (difference == 3)
status = "sophomore";
else if (difference == 4)
status = "freshman";
cout << " " << name << ", your status: " << status << endl;
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started