View the step-by-step solution to:

My code is below. I am looking for guidance as to how to fix the error I am receiving.

My code is below. I am looking for guidance as to how to fix the error I am receiving.


#include <iostream>

#include <string>

using namespace std;


int main() {

  string months[] = {"jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"};

  int days[] ={31,28,31,30,31,30,31,31,30,31,30,31};

  int num, years;

  while(true) {

    cout << "Please enter a day of the year (0 to exit): ";

    cin >> num;

    if(num <=0) {

      break;

    }

    years = num/366;

    num %= 365;

    if(years > 0) {

      cout << years << "year";

      if(years > 1) {

        cout << "s";

      }

      cout << endl;

    }

    if(num == 0) {

      cout << "dec 31" << endl;

    }

    else {

      for(int i = 0; i < 12; ++i) {

        if(num <= days[i]) {

          cout << months[i] << " " << num << endl;

          break;

        }

          num -= days[i];

          }

          }

          }

          cout << "Thanks for playing!" << endl;

          return 0;

          }

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question