#include <iostream>
using namespace std;
void getMonthName(int monthNum);


void main()
{
    int month, i=0;

    cout << "Enter a month " << endl;
    cin >> month;

    while (!cin.good() && i <3) {
            cout << " Bad input.\n";
            cin.clear();
            cin.ignore(80,'\n');
            cout << " Try again: ";
            cin >> month;
            i++;
    }
      while (!cin.good()) {
            cout << " try enter a number.\n";
            cin.clear();
            cin.ignore(80,'\n');
            cout << " 1 for Jan: ";
            cin >> month;

    }

       cout <<getMonthName(month)<<endl; ****** keep getting a error for this line. why?

}

void getMonthName (int monthVal) // month name
{
    int num = monthVal;
    switch (num)
    {
        case 1: cout<<"January";
          break;
        case 2: cout<<"February";
          break;
        case 3: cout<<"March";
          break;
        case 4: cout<<"April";
          break;
        case 5: cout<<"May";
          break;
        case 6: cout<<"June";
          break;
        case 7: cout<<"July";
          break;
        case 8: cout<<"August";
          break;
        case 9: cout<<"September";
          break;
        case 10: cout<<"October";
          break;
        case 11: cout<<"November";
          break;
        case 12: cout<<"December";
          break;
    }}

help with this error message. i dont know how to fix it. thanks

Recommended Answers

All 10 Replies

  1. Saying "an error" isn't good enough, copy and paste the actual error message(s).

  2. Use code-tags when posting code, then it's all nice and neat.

  3. main returns an int, not void.

cout <<getMonthName(month)<<endl;

You can't print a void!
Maybe just call the function and let it do all the printing.

error C2563: mismatch in formal parameter list
error C2568: '<<' : unable to resolve function overload

ok that problem is solved. what i should't of done was put<<endl; at the end.

i am stuck at this new problem.

here is my problem: the user input a started date for a year, and let said Jan and a year 2000. so Jan 1 2000 started on sunday and ends on monday.

how do i do a loop so it will calculated the correct start date for any given month follows?
so

ok that problem is solved. what i should't of done was put<<endl; at the end.

i am stuck at this new problem.

here is my problem: the user input a started date for a year, and let said Jan and a year 2000. so Jan 1 2000 started on sunday and ends on monday.

Actually, your problem is English. "user input a started date for a year" is hard to decipher. And "let said Jan and a year 2000" is undecipherable.

"so Jan 1 2000 started on sunday and ends on monday" is completely untrue. 1-Jan-00 was a Saturday. To start on Sunday and end on Monday there could only be 30 days in the month. Did you actually look at a calendar?

how do i do a loop so it will calculated the correct start date for any given month follows?
so

for (month=1; month <inputMonth; month++) maybe? Or something like that...

I am sorry for my poor English.
Please excuse me for that.
Now, can i have some advices on how to code this loop.

Thanks.

I am sorry for my poor English.
Please excuse me for that.

We have no problem with poor English as long as you try to make yourself understood. I was hoping you'd try to explain again what you said before. Since you didn't, I'll attempt to help based on what I think you want.

Now, can i have some advices on how to code this loop.

Make an array of 12 values to represent the number of days in each month. Then you use the for loop to add these values to a variable that will contain the number of days from one date to the next.

Be sure to read the post at the top of the forum titled Read Me: Read This Before Posting.

i can't use array or string, it is not allow on this assignment.

here is what i have so far from my program.
a example of the output:
ask for a year : (input) 2000
ask for a day of the week for Jan. 1st : (input)6 for Sat.
ask for a particular month's calender from this year: (input)1 for Jan.

then, my program prints the calender for Jan.

My concern is what if the input is not Jan.
How do i derive a correct algorithm that will calculated the day of the week for any month. so i can use that and print the correct calender.

i have setup a function call getDay(year,month,inputDayOfWeek)
i know i need to used the days for each month, the total days from a year and the day of the week from Jan. in order to calculate any day of the week but, i dont' know how to code the rest.

i look at Jan. 2000 and if i used this the number of days before Feb 1st. mod 7 i can get the correct day of the week for Feb.
31%7 = 3
and Feb, 01 2000 does start on the Tuesday.
i apply that method to March and it works also.

but if it is not year 2000, for example 2001. than this method wouldn't work?

this is where i stuck on right now.

Thank You for the help, Waltp

Read the last line of my post, please.

> but if it is not year 2000, for example 2001. than this method wouldn't work?
a normal year has 365 days, a leap year has 366.
if in year n, jan 01 is a monday, jan 01 n+1 would be a tuesday if n is not a leap year ( 365%7 == 1 ) and a wednesday if n is a leap year.
jan 01 n-1 would be a sunday if n-1 is not a leap year and a saturday if n-1 is a leap year.
keep doing modulo 7 arithmetic all the way. you could even use modulo 7 values for days in a month; jan : 3, feb : 0/1, mar : 3, apr : 2 etc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.