Question: error with if -else; and when i do change it around and it compiles; it outputs both sentences. #include using namespace std; int main() {
error with if -else; and when i do change it around and it compiles; it outputs both sentences.
#include
using namespace std;
int main()
{
string name;
int gradYear, currentYear, status, difference;
int freshman, sophmore, junior, senior;
// screen 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
// Calculate and output a graduate
{
if (gradYear < currentYear)
{cout << name << ", your status: graduated" ;}
cout << endl;
// If gradYear = 0, then output "not in college yet"
else gradYear = 0;
{cout << name << ", your status: not in college yet";}
cout << endl;
}
if (gradYear > currentYear)
{
difference = gradYear - currentYear;
if (difference == 1){
status = senior;}
else if (difference == 2){
status = junior;}
else if (difference == 3){
status = sophmore;}
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
Get step-by-step solutions from verified subject matter experts
