Code not working

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
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class weather_report
{
	int *dd;
	int *hightemp,*lowtemp,*amount_rain,*amount_snow;
	static int count;
	public:
		weather_report()
		{
		  dd=new int(99);
		  hightemp=new int(999),
		  lowtemp=new int (-999);
		  amount_rain=new int (0);
		  amount_snow=new int (0);
		}
		weather_report(weather_report &R)
		{
			dd=R.dd;
			hightemp=R.hightemp;
			lowtemp=R.lowtemp;
			amount_rain=R.amount_rain;
			amount_snow=R.amount_snow;
			count++;
		}
		void getdata()
		{
			cout<<"\n\t\t Enter day of month ";
			cin>>*dd;
			cout<<"\n\t\t Enter hightemp";
			cin>>*hightemp;
			cout<<"\n\t\t Enter lowtemp";
			cin>>*lowtemp;
			cout<<"\n\t\t Enter amount rain";
			cin>>*amount_rain;
			cout<<"\n\t\t Enter amount snow";
			cin>>*amount_snow;
			count++;
		}
		void  putdata()
		{
			cout<<"\n"<<*dd<<"\t\t"<<*hightemp<<"\t\t"<<*lowtemp;
			cout<<"\t\t"<<*amount_rain<<"\t\t"<<*amount_snow<<"\n";
		}
		static void dis()
		{
			cout<<count;
		}
};
int weather_report:: count=0;
void main()
{
	int ch,day;
	int menu();
	char c;
	clrscr();
	int i=1;
	weather_report WR1[30];
	do
	{
	   //	clrscr();
		switch(menu())
		{
			case 1:
					weather_report wr;
					WR1[i]=wr;
					cout<<"\n\t\t default data set";
					i++;
					break;

			case 2:
					WR1[i].getdata();
					cout<<"\n\t\t Manually data set";
					i++;
					break;
			case 3: clrscr();
					cout<<"\n\n\t\t The Information of ";
					weather_report::dis();
					cout<<"days\n\n";
					cout<<"\n Day Of month\thightemp\tlowtemp\t  amount rain\tamount rain\n";
					for(int j=1;j<i;j++)
					{
					WR1[j].putdata();
					}
					break;
			case 4: exit(0);
					break;
		}
		getch();
		clrscr();
	}while(ch!=4);

	getch();
}


int menu()
{
		cout<<"\n\t\t====================================\n";
//		cout<<"\n\t\t____________________________________";
		cout<<"\n\t\t	1. Set Default values\n";
		cout<<"\n\t\t	2. Enter manually\n";
		cout<<"\n\t\t	3. Create Weather Report\n";
		cout<<"\n\t\t\t 4. Exit";
		cout<<"\n\t\t====================================\n";
		cout<<"\n\t\t           Enter choice";
		int ch;
		cin>>ch;
		return(ch);

}


Any idea why this is not working? It says main has to have return int. cout not declared in this scope. I'm a complete noob so I dont know what this means. And I think it is not loading the header files properly. Please help!
what makes you think it's not working?
I have no idea! As I said I am a beginner!
it should be

1
2
3
4
5
int main
{
//code
return 0;
}


You should also move theint menu above int main
closed account (10oTURfi)
Its not working because he isnt using namespace std;. Also, on modern compilers iostream file doesnt have .h extension.

And it leaks memory :)

Also, main function cant be defined with void return type.

Its either:
int main() int main(int argc, char* argv[]) int main(int argc, char** argv)
Last edited on
Hey guys thanks a lot for the help! I made the changes you guys pointed out. But I'm getting the following error: stdlib: no such file or directory. How do I install it? I'm using codeblocks 10.05. Should I get a new IDE?
closed account (10oTURfi)
Its cstdlib in C++
I have no idea! As I said I am a beginner!


That's not what I meant.

I mean you can obviously tell that it's not working, but how can you tell?

Hint: "it's not working" is not descriptive. It tells us nothing about the problem. Tell us what the actual problem is.

(EDIT: the above is for future reference, anyway, since other people were able to help)
Last edited on
Still getting the following errors:
1. error conio: no such file or directory
2. ::main must return int
3. Bunch of errors that say getch was not declared in this scope/clrscr was not declared in this scope. What does this mean?
closed account (10oTURfi)
1. I actually dont recall such header. Is it non standard? Remove that #include line
2. You didnt fix main function. It must be of return type int and return integral value (usually return 0;)
3. I dont think there exists function called clrscr. You can use system("cls") on windows or system("clear") on linux for this. However, it is considered bad habbit. (there is article about clearing screen)
Also I do not see need for getch() in this example. Remove it?
closed account (1vRz3TCk)
adijo wrote:
Still getting the following errors:
1. error conio: no such file or directory
2. ::main must return int
3. Bunch of errors that say getch was not declared in this scope/clrscr was not declared in this scope. What does this mean?

I would say that there is a incompatibility between your learning material and your compiler. It looks like you are using an old source for information and a new compiler.
Okay guys, thanks a lot for the help! Really appreciate it!
I have one more doubt. In this program why is everything passed by reference? Can't I do the same thing without pointers? And what is the second constructor that has been used here?
Topic archived. No new replies allowed.