Help with my code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
string input, subject, year;
bool validSubject = true, validYear = true;
cout << "Enter two characters: ";
cin >> input;
if (input[0] == 'M') subject = "Mathematics " ;
else if (input[0] == 'C') subject = "Computer Science " ;
else if (input[0] == 'I') subject = "Information technology ";
else validSubject = false;
int status = input[1] - '0';
switch(status)
{
case 1: year = "Freshman" ; break;
case 2: year = "Sophomore"; break;
case 3: year = "Junior" ; break;
case 4: year = "Senior" ; break;
default: validYear = false;
}
if ( validSubject && validYear ) cout << subject + year << endl;
if ( !validSubject ) cout << "Invalid major code" << endl;
if ( !validYear ) cout << "Invalid status code" << endl;
}
|
Topic archived. No new replies allowed.