Simple Code

The Below Coded Doesn't work


#include<iostream.h>
#include<conio.h>
Class Ex
{
public:
int a;
void get()
{
cout<<"Enter The Values";
cin>> a
}
void chek()
{
if (a==1)
{
cout<<"Monday";
}
else if (a==2)
{
cout<<"Tuesday";
}
else if (a==3)
{
cout<<"Wednesday";
}
else if (a==4)
{
cout<<"Thursday";
}
else if (a==5)
{
cout<<"Friday";
}
else if (a==6)
{
cout<<"Saturday";
}
else if (a==7)
{
cout<<"Sunday";
}
else
{
cout<<"Enter Correct Values i.e Numbers From 1-7";
}
}
void main
Ex e ;
e.get();
e.chek();
}
Your main function is missing the opening {.
And it's missing parentheses.
Your Class definition is also missing a semicolon at the end.
Also it is better to use names of headers that follow the C++ standard. That is instead of

#include<iostream.h>

you should write

#include<iostream>

And it would be also better if data member a would have private access.
Last edited on
And it would be also better if data member a would have private access.


I'd say this is mainly preference. But, since he does already have a setter (albeit named as "get"), might as well make it private.
And main doesn't return void.
Yes he should select something one either a is private and has a getter and setter ( if there is a requirement of them) or a is public and when it does not require a setter.

An example of class where data members are public could be a Point class.
Last edited on
Can Someone PLs Pls Pls write the correct code for this and post. as i am a begginer and i need a lot of help. i am just 12 yrs old.
Cmmon. give him a break:):)
SPARSH here u go:
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
    #include<iostream>
    #include<conio.h>
    class Ex
    {
     private:
             int a;
     public:
      void get()
     {
       cout<<"Enter The Values";
       cin>> a;
      }
    void chek()
    {
     if (a==1)
     {
      cout<<"Monday";
     } 
     else if (a==2)
     {
      cout<<"Tuesday";
     }
    else if (a==3)
    {
    cout<<"Wednesday";
    }
    else if (a==4)
    {
    cout<<"Thursday";
    }
    else if (a==5)
    {
    cout<<"Friday";
    }
    else if (a==6)
    {
    cout<<"Saturday";
    }
    else if (a==7)
    {
    cout<<"Sunday";
    }
    else
    {
    cout<<"Enter Correct Values i.e Numbers From 1-7";
    }
   }
    };
    int main()
    {
     Ex e ;
     e.get();
     e.chek();
     return 0;
    }

Please dont be discouraged!!!
THANKS A LOT ANIRUDH.
It would be better to have a switch satement rather than a great big if else if else staement.

Normally a set function puts some info into an object, whereas get retrieves info from the object.

I would reccommend that you do some reading through the tutorials on this website and elsewhere.

Any more questions don't be afraid to ask - wecan help.

Good luck!!
Topic archived. No new replies allowed.