I'm just starting to learn C++ for school, and I'm having trouble completing a school project requiring the use of if/else statements. The project requires code that works as: example of working code My code looks like this:
#include <iostream>
using namespace std;
int ontime;
int zip;
int work;
int main()
{
cout << "Welcome to the DIG3873 System." << endl;
cout << "Did the student submit the exam on time (Y/N)? ";
cin >> ontime;
if (ontime == 'Y' || 'y') {
cout << "Did the student zip the file (Y/N)? ";
cin >> zip;
if (zip == 'Y' || 'y') {
cout << "Did the student's code work as requested (Y/N)? ";
cin >> work;
if (work == 'Y' || 'y') {
cout << "Congratulations, YOU PASS. "<< endl;
} else if (work == 'N' || 'n') {
cout << "YOU FAIL " << endl;
} else {
cout << "Please enter a valid response. " << endl;
}
} else if (zip == 'N' || 'n') {
cout << "YOU FAIL " << endl;
} else {
cout << "Please enter a valid response. " << endl;
}
} else if (ontime == 'N' || 'n') {
cout << "YOU FAIL " << endl;
} else {
cout << "Please enter a valid response. " << endl;
}
}
Unfortunately, it's not working as I would have hoped. When it runs, it lets me answer the first statement, then just drops all the other cout statements and a bunch of "YOU FAIL"s and ends the program. We haven't learned anything beyond if/else statements, so I was pretty lost looking at similar coding issues where people recommended using loops instead. Sorry for such a beginner's issue with not understanding if/else statements, thanks!