Why is garbage coming?

Hello I am unable to do it correctly. can anyone help me in this. ( use turbo C++ only).

I have used the concept of Julian Day Number.
I am getting garbage in this program.

My code is:-
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
    #include <iostream.h>
    #include <conio.h>

    class day
    {
	    public:
	    int d, m, y;
      	void enter()
	{
		cout<<"Enter the Date (d, m, y format) \n";
		cin>>d>>m>>y;
	}
	    void calc(int &d, int &m, int &y, int days)
	{
		int a, b, c, f;
		long int e, jd;
		if(m==1||m==2)
		{
			y=y-1;
			m=m+12;
		}
		a=y/100;
		b=a/4;
		c=2-a+b;
		e=365.25*(y+4716);
		f=30.6001*(m+1);
		jd=c+d+e+f-1524;
		jd=jd+days;
		long int z1, a1, b1, d1;
		int  w1, x1, c1, e1, f1;
		z1=jd;
		w1=(z1-1867216.25)/36524.25;
		x1=w1/4;
		a1=z1+1+w1-x1;
		b1=a1+1524;
		c1=(b1-122.1)/365.25;
		d1=365.25*c1;
		e1=(b1-d1)/30.6001;
		f1=30.6001*e1;
		d=b-d-f;
		if(e<=13)
			m=e-1;
		else
			m=e-13;
		if(e>13)
			y=c-4715;
		else
			y=c-4716;
	}
	void disp()
	{
		cout<<"The new date is : "<<d<<" "<<m<<" "<<y;
	}
    };

    void main()
    {
	clrscr();
	int days;
	day A;
	A.enter();
	cout<<"Enter no. of days to be added ";
	cin>>days;
	A.calc( A.d, A.m, A.y, days);
	A.disp();
	getch();         
    }


But I am not getting any error in this program:-
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
     #include <iostream.h>
     #include <conio.h>
     int dat(long int jd)
     {	    long int z, a, b, d;
	    int  w, x, c, e, f;
	    z=jd;
	    w=(z-1867216.25)/36524.25;
	    x=w/4;
	    a=z+1+w-x;
	    b=a+1524;
	    c=(b-122.1)/365.25;
	    d=365.25*c;
	    e=(b-d)/30.6001;
	    f=30.6001*e;
	    return b-d-f;
     }
     int mont(long int jd)
     {	   
        long int z, a, b, d;
	int  w, x, c, e, f;
	z=jd;
	w=(z-1867216.25)/36524.25;
	x=w/4;
	a=z+1+w-x;
	b=a+1524;
	c=(b-122.1)/365.25;
	d=365.25*c;
	e=(b-d)/30.6001;
	if(e<=13)
	    return e-1;
	else
	    return e-13;
     }
     int yea(long int jd)
     {  
        long int z, a, b, d;
	int  w, x, c, e, f;
	z=jd;
	w=(z-1867216.25)/36524.25;
	x=w/4;
	a=z+1+w-x;
	b=a+1524;
	c=(b-122.1)/365.25;
	d=365.25*c;
	e=(b-d)/30.6001;
	if(e>13)
	      	return c-4715;
	else
	        return c-4716;
     }
     long int julian(int d, int m, int y)
     {
	int a, b, c, f;
	long int e, jd;
	if(m==1||m==2)
	{
	    y=y-1;
	    m=m+12;
	}
        a=y/100;
	b=a/4;
	c=2-a+b;
	e=365.25*(y+4716);
	f=30.6001*(m+1);
	jd=c+d+e+f-1524;
	return jd;
     }
     long int add(long int jd, int days)
     {
	return jd=jd+days;
     }
     void main()
     {
	clrscr();
	long int jd;
	int date, month, year, days, ndate, nmonth, nyear;
	cout<<" Enter the date (d, m, y)";
	cin>>date>>month>>year;
	cout<<"Enter days to add";
	cin>>days;
	jd=julian(date, month, year);
	jd=add(jd, days);
	ndate=dat(jd);
	nmonth=mont(jd);
	nyear=yea(jd);
	cout<<"\n New date=:"<<ndate<<" "<<nmonth<<" "<<nyear;
	getch();
     }


But the problem is, I have to use classes and objects.

Thanks a lot.
For your first program if you did a couple of things you might be able to find the problems.

First get a newer compiler. Turbo C++ is to outdated to be used to create a "modern" program.

Second when you get this new compiler make sure it is generating the maximum number of warnings, and fix the warnings the compiler generates.

main.cpp||In member function ‘void day::calc(int&, int&, int&, int)’:|
main.cpp|14|warning: declaration of ‘y’ shadows a member of 'this' [-Wshadow]|
main.cpp|14|warning: declaration of ‘m’ shadows a member of 'this' [-Wshadow]|
main.cpp|14|warning: declaration of ‘d’ shadows a member of 'this' [-Wshadow]|
main.cpp|30|warning: variable ‘f1’ set but not used [-Wunused-but-set-variable]|
main.cpp|56|error: ‘::main’ must return ‘int’|
main.cpp||In function ‘int main()’:|
main.cpp|58|error: ‘clrscr’ was not declared in this scope|
main.cpp|66|error: ‘getch’ was not declared in this scope|


Sorry but in my school only turbo C++ is used that's why I asked for only Turbo C++.
Anyways thanks for your help.
You probably have a problem with your math. Maybe there is some coefficient wrong, maybe there is a missing parenteses somewhere, maybe you have problem with truncating doubles or integer division.

Nobody will be able to spot a mistace because code as it now is arcane mess of math expressions. The mixture of magic numbers and one-letter variabes. This code is write-only: no one will ever read or debug it because it is totally unsupportable. Lack of comments or sensible variable names prevens people from guessing what specific part of code is intended to do and because of that they cannot find any differencies between it and what code is actually doing.

Also there is not many people wanting to look up what was allowed and what was not in language standard which was made completely obsolete more than 15 years ago in previous millenium. And not to mention Turbo-C++ which is notorious for Standard violations.
Topic archived. No new replies allowed.