# Help with code for simple Y2K problem

• 03-05-2003
Mule
Help with code for simple Y2K problem
I have to write code for this:
A college has an “academic year” and counts four semesters in order of Fall, Spring, First Summer and Second Summer as an academic year. The Fall, 2002 semester was the first semester of Academic Year 2003.

Your program should accept as input an unknown number of 3 digit numbers representing the current semester. For each input record, output the semester in the form given in the first column above.

Inputs:
031
033
980

Output:
Semester Code
Fall, 2002 031
First Summer, 2003 033
Spring, 1998 982

As you can see, it's really a Y2K problem. My code does ok exept it stays in the loop and I can't get the output to resemble the example above, with the "Semester" then "Code" and the output below it. Can someone help me with that?
• 03-05-2003
R.Stiltskin
Code:

``` #include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() {     int x, y, z;                     cout<<"Enter semester code or \"q\" to quit > "<<endl;                                 // actually, any non-numeric character will break out of the loop     while (cin >> x)     { //      if ((x / 10) >= 0 && (x / 10) <= 50) //          y = (x / 10) + 2000;                                 //      else if ((x / 10) == 1 || (x /10) >= 51) //          y = (x / 10) + 1900;                                 //        isn't x/10 always >= 0?                                 //        where you break between 1900's & 2000's is arbitrary, right?                                 //  isn't this simpler:         if (x/10 <= 50)             y = x/10 + 2000;             else y = x/10 + 1900;         z = x % 10;                                 //        you had some unneeded brackets         cout << "Semester" <<"              "<<  " Code" <<right <<endl;         if (x % 10 == 1)             cout << "Fall, "<< y - 1<<"              "<< setw(3) << setfill('0')<< x <<right <<endl;         if (x % 10 ==2)             cout << "Spring, "<< y << "            "<<setw(3) <<right << setfill('0') <<  x <<endl;         if (x % 10 == 3)             cout << "First Summer, "<< y << "      "<<setw(3) << right << setfill('0') << x <<endl;         if (x % 10 == 4)             cout << "Second Summer, "<< y << "    "<<setw(3) << right << setfill('0') << x <<endl;         cin.ignore();          //        this discards the newline characters entered by user                                 //        then, prompt for the next entry before exiting loop         cout<<"Enter code or \"q\" to quit > "<<endl;     }     return 0; }```
• 03-05-2003
Mule
Help with code for simple Y2K problem
Thank you R.Stiltskin !! I do appreciate your advice.
How would I only show this line

cout << "Semester" <<" "<< " Code" <<right <<endl;

only once, on top of the output?
• 03-05-2003
R.Stiltskin
You could move it up to just before the while loop, but since all the output is going to the screen, it'll still be broken up by prompts and input lines between the output lines.

Otherwise, you would have to send the output to a file, and print it afterwards.