Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given a number, calculate how many years into the future it is, and what date. Assume no leap years. For example: Please enter a day

Given a number, calculate how many years into the future it is, and what date. Assume no leap years.

For example:

Please enter a day of the year (0 to exit): 1

jan 1

Please enter a day of the year (0 to exit): 365

dec 31

Please enter a day of the year (0 to exit): 366

1 year

jan 1

Please enter a day of the year (0 to exit): 0

Thanks for playing!

This is C++ intro to programming course. Can you tell me what I am doing wrong? Please don't use boot tool

#include

#include

using namespace std;

int main() {

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

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

int num;

int years;

int day;

while(true){

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

cout << num;

cin >> num;

cout <

if (num <= 0){

break;

}

years=num/366;

num %= 365;

if(years > 0){

cout <

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 <

break;

}

num-=days[i];

cout << num <

}

}

}

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

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions