This program is supposed to display the months as well as th

This program is supposed to display the months as well as the corresponding days to the total days of those months in a different function C++

However, i attempted the problem and it wont iterate through the days that it needs to do.

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

void displayCalendar(int d[12], string m[12]);

main()
{
int days[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
string months[12] = {\"January\",\"February\",\"March\", \"April\", \"May\", \"June\",\"July\",\"August\",
\"September\",\"October\",\"November\",\"December\"};

displayCalendar(days,months);
}

void displayCalendar(int d[12], string m[12])
{
    cout << setw(7) << \"Month\" << setw(7) << \"Days of month\" << endl;
    cout << setw(7) << \"-----\" << setw(7) << \"-------------\" << endl;
       for(int s = 0; s < 12; s++)
       {
       cout << setw(7) << m[s] << \" \";
       for(int w = 0; w < 1; w++)
       {
       cout << setw(7) << w[d] << \" \";
   }
   cout << \"\ \";
    }
}

Solution

Program:

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void displayCalendar( string m[],int d[]);
main()
{
string months[] = {\"January\",\"February\",\"March\", \"April\", \"May\", \"June\",\"July\",\"August\",
\"September\",\"October\",\"November\",\"December\"};
int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};


displayCalendar(months,days);
}
void displayCalendar(string m[],int d[])
{
int w=0; // Here we are initializing the value of w as zero
cout << setw(7) << \"Month \" << setw(7) << \"Days of month\" << endl;
cout << setw(7) << \"-----\" << setw(7) << \"----------------\" << endl;
for(int s = 0; s <12; s++)
{
cout << setw(7) << m[s] << \" \";

if(w <12) // Here we are checking the condition that if w< 12 or not if it is true then print d[w] value
{
cout << setw(7) << d[w] << \" \";
w++; // Here we are incrementing the value of w
}

cout << \"\ \";
}
}

Output:

Month Days of month
-----------------------------------
January 31
February 28
March 31
April 30
May 31
June 30
July 31
August 31
September 30
October 31
November 30
December 31

This program is supposed to display the months as well as the corresponding days to the total days of those months in a different function C++ However, i attemp
This program is supposed to display the months as well as the corresponding days to the total days of those months in a different function C++ However, i attemp

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site