please help !

can u please find error in the program........it runs upto enter month and continues without stopping......it executes infinite times in turbo c++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

#include<iostream>
using namespace std;
int step1(int);
void month_name(int);
int no_days(int,int);
int leap(int);
int main()
{
restart:

cout<<"enter year";
unsigned int y,m;
cin>>y;
int x;
x=step1(y);
int month[14][12]={1,4,4,7,2,5,7,3,6,1,4,6,
2,5,5,1,3,6,1,4,7,2,5,7,
3,6,6,2,4,7,2,5,1,3,6,1,
4,7,7,3,5,1,3,6,2,4,7,2,
5,1,1,4,6,2,4,7,3,5,1,3,
6,2,2,5,7,3,5,1,4,6,2,4,
7,3,3,6,1,4,6,2,5,7,3,5,
1,4,5,1,3,6,1,4,7,2,5,7,
2,5,6,2,4,7,2,5,1,3,6,1,
3,6,7,3,5,1,3,6,2,4,7,2,
4,7,1,4,6,2,4,7,3,5,1,3,
5,1,2,5,7,3,3,5,1,4,6,2,
4,6,2,3,6,1,4,6,2,5,7,3,5,
7,3,4,7,2,5,7,3,6,1,4,6};

cout<<"enter month(1-12) ";
month_input:
cin>>m;
if(m<1||m>12)
{
cout<<"enter a valid month(1-12)";
goto month_input;
}
cout<<" ";
month_name(m);
cout<<" "<<y<<"mon tue wed thu fri sat sun";
int j =month[x-1][m-1], days = no_days(m,y);

for(int i=0;i<j-1;i++)
cout<<" ";
for(int i=1;1<=days;i++)
{
cout<<i<<" ";
if(j==7)
{
cout<<" ";
j=1;
}
else
j++;
}
cout<<"try for another month ?(y/n)";
char ch;
cin>>ch;
if(ch=='y'||ch=='Y')
goto restart;
}
int step1(int y)
{
int x= y%7;
x+=(y-1)/4;
x-=(y-1)/100;
x+=(y-1)/400;
x=x%7;
if(x==0)
x=7;
if(leap (y))
x+=7;
return x;
}
void month_name(int m)
{
switch(m)
{
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;
}
}
int no_days(int mon,int y)
{
int d;
switch (mon)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:d=31;
break;
case 4:
case 6:
case 9:
case 11:
d=30;
break;
case 2:if(leap(y))
d=29;
else
d=28;
break;
}
return d;
}
int leap (int y)
{
if(y%100==0)
if(y%400==0)
return 1;
else
return 0;
else if(y%4==0)
return 1;
else
return 0;
}




enter year
2014
enter month
5


after this it doesnt stop.......and give infinite results.....
Last edited on
Uhm...I see that you are saying goto month_input, but I couldn't find a month_input:.

It is also bad practice to use goto. It makes your code very hard to read and other issues too.
You should use functions instead for that.

http://xkcd.com/292/

Edit: The only time I would use them is to break out of multiple loops.

Edit 2: Oops, I just found mounth_input: ...
Last edited on
Why are you starting a new thread?
You haven't fixed the issues pointed out in your other thread:
http://www.cplusplus.com/forum/general/138867/
then could u please correct the code.......mean a new code to generate forever calendar....please
i have made certain changes.......could u please help....im new actually..........
Why should I correct your code for you when I told you what was wrong and you start a new thread with the same errors as before, ignoring the errors I pointed out?
sorry actually i didn't knew that any thread can be modified also thats why i started a new.......and i have also made certain changes as suggested.....

Last edited on
please help me out .i have to submit this before 1 aug.......
for(int i=1;1<=days;i++){

And this gives me an error,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
	int month[14][12]={	1,4,4,7,2,5,7,3,6,1,4,6,
					2,5,5,1,3,6,1,4,7,2,5,7,
					3,6,6,2,4,7,2,5,1,3,6,1,
					4,7,7,3,5,1,3,6,2,4,7,2,
					5,1,1,4,6,2,4,7,3,5,1,3,
					6,2,2,5,7,3,5,1,4,6,2,4,
					7,3,3,6,1,4,6,2,5,7,3,5,
					1,4,5,1,3,6,1,4,7,2,5,7,
					2,5,6,2,4,7,2,5,1,3,6,1,
					3,6,7,3,5,1,3,6,2,4,7,2,
					4,7,1,4,6,2,4,7,3,5,1,3,
					5,1,2,5,7,3,3,5,1,4,6,2,
					4,6,2,3,6,1,4,6,2,5,7,3,5, //!!
					7,3,4,7,2,5,7,3,6,1,4,6};


You got all about these in your last post by AbstractionAnon.
I don't know why you don't care to fix it.

^
|
????????
|
V
sorry actually i didn't knew that any thread can be modified also thats why i started a new.......and i have also made certain changes as suggested
Last edited on
even this doesnt make a change......i tried it.....problem is same!!!!
check the array, i think the crash is from there
and, debugging is very useful
Line 47: Your loop will never stop. Your termination condition is 1<=days.
One will always be less than days.
Topic archived. No new replies allowed.