this question want the calender,with a number of week and days.
in germany,the 1st week is started with monday.i have a problem with the year 2000 and the month is in january.when i type it, it
shows the 1st week is in 10th.january 2000,
it should be on 3rd january 2000.
some of the years have 53 weeks per year and some year have 52 weeks only. so there is a problem when it has only 53weeks..
i already try to find the error,but i can't find it.i'm using dev c++..
thank you for your help..

#include <iostream>
#include <stdlib.h>
#include <iomanip>
using namespace std;
bool valid(int year, int month2);
bool leapyear(int year);
bool func_wdays(int n);
bool calendardarst(int week, int weekday, int  weeknum,int month2);
int first_day(int year);
int daysvmonth2(int year, int month2);
    int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
    int day=0, year=0, month2=0;
    int fisrtday, wday, wanz, vmt, week, wende;
    cout<<"This program calculates the weeknday, the first days in the year, the weeknday in the month2 of the yeares, the week, with which the month2 starts\n"
        <<"The week with that of the month2 finishes and the number of the weekn in the month2.\n"
        <<"please, they give the year and the month2 one, in which the above-mentioned data should be shown,\n"
        <<"finally the calender will come out with month and days\n"
       <<"\nplease give a year : ";
    cin>>year;
    cout<<"please give a month: ";
    cin>>month2;
    if(valid(year, month2)){
        fisrtday=first_day(year);
        cout<<"that date is valid\n"
            <<"the fisrt day of a year "<<year<<"is a: ";
        func_wdays(fisrtday);
        vmt=daysvmonth2(year, month2);            //vormonth2s days
        week=(vmt+fisrtday)/7+(fisrtday<=3);        //die week in der der erste liegt
        if(week==0)
        {
            fisrtday=first_day(year-1);
            vmt=daysvmonth2(year-1, 12);
            wday=(fisrtday+vmt)%7;
            wanz=1+(days[month2]+wday-7)/7+((days[month2]+wday-7)%7>0);
            week=(vmt+fisrtday)/7+(fisrtday<=3);        //die week in der der erste liegt
            week=(wanz-1)+week ;
        }
        cout<<"\n the fisrt day of that month is on: "<<week<<"calendar week"<<endl;
        vmt=daysvmonth2(year, month2);
        if(month2==1)
            wday=first_day(year);
        else
            wday=(first_day(year)+vmt)%7;            //weeknday des month2
        cout<<"the fisrt day of that month is: ";
        func_wdays(wday);
        wanz=1+(days[month2]+wday-7)/7+((days[month2]+wday-7)%7>0);    //anzahl der weekn im month2
        cout<<"\nthe number of that week is: "<<wanz<<endl;
        //soo und weiter geht's :)) investigation der week with the month2 until end
        wende=(wanz-1)+week;
        cout<<"the week in the month2 end in this week: "<<wende<<endl;
        calendardarst(week, wday, wanz, month2);
        
    }
    else{
        cout<<"das von ihnen eingegebene Datum ist unvalid, das Programm wird nun beendet.\n";
        exit(0);
    }
    cout<<endl;
    
system("PAUSE");
main ();  
}

bool func_wdays(int n){
    switch(n){
        case 0: cout<<"Mo "; break;
        case 1: cout<<"Di"; break;
        case 2: cout<<"Mi"; break;
        case 3: cout<<"Do"; break;
        case 4: cout<<"Fr"; break;
        case 5: cout<<"Sa"; break;
        case 6: cout<<"So"; break;
    }
    return true;
}

int daysvmonth2(int year, int month2){
    int n=0;
    cout<<year<<endl;
    if(leapyear(year))
        days[2]=29;
    else
        days[2]=28;
    for(int i=1; i<month2; i++){
        n+=days[i];
    }
    cout<<days[2]<<endl;
    return n;
}

bool valid(int year,int month2){
    if(month2>12||month2<1)
        return false;
    if(year<1583)
        return false;
    return true;
}
bool leapyear(int year){
        if (year%4==0 && year%100!=0 || year%400==0)
            return true;
        else
            return false;
 }
int first_day(int year){
    int n=77, month=1, a=0;
    int month2=1, day=1;
    for(int i=1583; i<year; i++){
        if(leapyear(i))
            n+=366;
        else
            n+=365;
        a++;
    }
    for(int i=month;i<=month2-1;i++){
        if(i==2){
            if(leapyear(year))
                days[2]=29;
            else
                days[2]=28;
        }
        n+=days[i];
    }
        n+=day;
    n=(4+n)%7;
    return(n);
}

bool calendardarst(int week, int weekday, int  weeknum,int month2){
    int arr[42];
    cout<<endl<<endl;
    for(int i=0, buff=1; i<42; i++ ){
        if(buff<(days[month2]+1)&&weekday<=i)
        {
            arr[i]=buff;
            buff++;
        }
        else
            arr[i]=0;
    }
    //ausgabe
    cout<<setw(4)<<"Wo |";
    for(int i=week, j=week; j<=(weeknum+week-1);j++,i++)
    {
        cout<<setw(3)<<i;
        if(i==52&&i==53)
            i=0;
        if(i==53)
        i=0;
        continue;
    
     }
    cout<<"\n-----";
    for(int i=0;i<weeknum;i++)
        cout<<"----";
    cout<<"\nMo |";
    for(int i=0, j=0, k=1, z=0; i<42; i++){
        if(j==6)
        {
            cout<<endl;
            func_wdays(k);
            cout<<" |";
            k++;
            j=0;
            z-=41;
        }
        if(arr[z]==0)
            cout<<setw(3)<<" ";
        else
            cout<<setw(3)<<arr[z];
        j++;
        z+=7;
    }
    return true;
}

I think it worked ok for me. I can't read German so I guessed at the prompts. Below for Jan 2000

Dieses Programm errechnet den Wochentag, des ersten Tages im Jahr, den Wochentag
 im Monat des Jahres, die Woche, mit der der Monat anfaengt
Die Woche mit dem der Monat endet und die Anzahl der Wochen im Monat.
bitte geben sie das Jahr und den Monat ein, in denen die o.g. Daten angezeigt we
rden sollen
Anschliessend wird der Kalender des Monats angezeigt
bitte geben Sie das Jahr ein: 2000
bitte geben Sie nun den Monat ein: 1
das Datum ist gueltig
der erste Tag des Jahres, 2000ist der: Sa2000
29
1999
28

 der erste des Monats liegt in der: 52Kalender woche
2000
29
der erste des Monats ist der: Sa
 die Anzahl der Wochen in dem Monat betraegt: 6
die Woche in der der Monat endet ist die Woche: 57


Wo | 52  1  2  3  4  5
-----------------------
Mo |     3 10 17 24 31
Di |     4 11 18 25
Mi |     5 12 19 26
Do |     6 13 20 27
Fr |     7 14 21 28
Sa |  1  8 15 22 29
So |  2  9 16 23 30
Press any key to continue . . .

urm but it doesn't work with december 1953.it should be the last week lie on weeks53 but in this programm, it lie in 1st week.

from the question above,

cout<<setw(4)<<"Wo |";
    for(int i=week, j=week; j<=(weeknum+week-1);j++,i++)
    {
        cout<<setw(3)<<i;
        if(i==52&&i==53)
            i=0;
        if(i==53)
        i=0;
        continue;
    
     }

but in my aufgabe07.cpp,

is

for(int i=woche, j=woche; j<=(woanzahl+woche-1);j++, i++){
        cout<<setw(3)<<i;
        if(i==52||i==53)
            i=0;

when i change the sign || to && and add another command,it got a problem with jan 1989, when i did'n change,it's running ok.

the file aufgabe7.cpp is running ok with jan 2000 and desember 1999,but it doesn't work for desember 1953.

please try with desember 1953 and january 1954.
and also desember 1997 and january 1998.

you will see the difference..
thanks..

urm...for your info, when the last day in a year is in thursday,there will be a new week,which is 1st week for the incoming year.

please,somebody help me..

I haven't had time to look at it today, but since I can not read a word of German I am probably not the best person to even try. I don't know if anyone else here read/write German or not. Or if you could translate the program into English ... :)

okies..:) this is the file which is already translate.
the question and .cpp program.

I haven't had time to look at it today, but since I can not read a word of German I am probably not the best person to even try. I don't know if anyone else here read/write German or not.

I wish I could speak it fluently, but I know enough to get by... ;)

okies..:) this is the file which is already translate.
the question and .cpp program.

I don't find the translation much better; no offense, but the grammar makes it really hard to understand.

Your code isn't much better off; although based on my personal observation, it seems like the code is needlessly longer than it should be.

Some things I noticed:

system("PAUSE");

main ();  

}

To pause the program, you'd be better off using a portable function like cin.get() . And why do you have that last main() statement at the end of the program? What purpose does it serve?

You might be better off using enums or an const array of strings, and then print out the correct element rather than using a lengthy switch() statement:

bool func_wdays(int n){

    switch(n){

        case 0: cout<<"Mo "; break;

        case 1: cout<<"Tue"; break;

        case 2: cout<<"Wed"; break;

        case 3: cout<<"Thu"; break;

        case 4: cout<<"Fr"; break;

        case 5: cout<<"Sa"; break;

        case 6: cout<<"So"; break;

    }

    return true;

}

Hope this helps

Jan 1954 -- Only the week numbers are incorrect, days are ok.

Dec 1953 -- everything looks ok

please give a year : 1953
please give a month: 12
that date is valid
the fisrt day of a year 1953is a: Thu1953
28

 the fisrt day of that month is on: 49calendar week
1953
28
the fisrt day of that month is: Tue
the number of that week is: 5
the week in the month2 end in this week: 53


We | 49 50 51 52 53
-------------------------
Mo |     7 14 21 28
Tue |  1  8 15 22 29
Wed |  2  9 16 23 30
Thu |  3 10 17 24 31
Fr |  4 11 18 25
Sa |  5 12 19 26
So |  6 13 20 27
Press any key to continue . . .

not sure if the week numbers are correct or not. The days are ok

This program calculates the weeknday, the first days in the year, the weeknday
n the month2 of the years, the week, with which the month2 starts
The week with that of the month2 finishes and the number of the weeks in the mo
th2.
please, enter the year and the month in which the above-mentioned data should b
 shown,
finally the calender will come out with month and days

please enter a year : 2000
please enter a month: 1
that date is valid
the fisrt day of a year 2000is a: Sa
 the fisrt day of that month is on: 52calendar week
the fisrt day of that month is: Sa
the number of that week is: 6
the week in the month2 end in this week: 57


We | 52 53  1  2  3  4
-----------------------------
Mo |     3 10 17 24 31
Tue |     4 11 18 25
Wed |     5 12 19 26
Thu |     6 13 20 27
Fr |     7 14 21 28
Sa |  1  8 15 22 29
So |  2  9 16 23 30
Press any key to continue . . .

this problem already solved by my friend. thanks for your help...

:)

this problem already solved by my friend. thanks for your help...

:)

Great News -- glad you found someone that could help you :)

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.