what is error of this code please correct erroe and find solution

#include<iostream.h>
//#include<conio>
#include<string.h>
//using namespace std;
class television
{
public:
int model;
int price;
int size;
int throw;
television()
{
model=size=price=0;
}
friend void operator>>(istream &din,television &tv)
{ int throw;
cout<<"\n\nEnter model : ";
din>>tv.model;
if(tv.model>9999)
{
throw tv.model;
}
cout<<"\n\nEnter size : ";
din>>tv.size;
if(tv.size<12 || tv.size>70)
{
throw tv.size;
}
cout<<"\n\nEnter price : ";
din>>tv.price;
if(tv.price<0 || tv.price>5000)
{
throw tv.price;
}
}
void set()
{
model=price=size=0;
}
friend void operator<<(ostream &dout,television &tv)
{
dout<<"\n\nModel : "<<tv.model;
dout<<"\n\nSize : "<<tv.size;
dout<<"\n\nprice : "<<tv.price;
}
};

void main()
{ int trycry;
television t;
trycry;
{
cin>>t;
}
catch();
{
cout<<"\n\nException caught";
t.set();
}
/*catch(float n)
{
cout<<"\n\nException caught";
t.set();
}
catch(double n)
{
cout<<"\n\nException caught";
t.set();
}*/
cout<<t;
//getch();
}

1. <iostream.h> doesn't exist on any modern compilers, use <iostream>
2. int throw; isn't legal. throw is a reserved word, you can't make a variable out of it.
3. You declare int throw twice. You can't declare anything twice.
4. You commented out "using namespace std" but didn't prepend std:: to anthing.
5. void main() shouldn't be allowed, main() should return an int
6. trycry; isn't a valid statement, I'm guessing you wanted to try but I have no idea what you wanted to do with cry;
7. After try, do not use a ;
8. A catch statement must have a parameter list. To catch anything, use (...).
9. After catch(...) you may not use a ;
10. Don't define friend functions within a class. They are external to the class (hence the definition of friend). Forward declare them only.

You really need to read your compilation errors. They will tell you everything that I just told you. The fact that you used void main() and <iostream.h> tells me that you are using something along the lines of Dev-C++. If that's the case, switch compilers to something that actually follows a C++ standard.
Topic archived. No new replies allowed.