C++/logical problem in c++
Expert: vijayan - 8/11/2009
Questionwhen i am running this code it is not taking input of year.why is this happening and how can i solve this problem?
#include<iostream.h>
class add
{
char name[40],rno[15],brch;
int yr;
public:
void getdata()
{
cout<<"\n enter name";
cin.getline(name,40);
cout<<"\n enter roll no";
cin.getline(rno,15);
cout<<"\n enter branch";
cin>>brch;
cout<<"\n enter year";
cin>>yr;
}
};
void main()
{
add a;
a.getdata();
}
Answer> #include<iostream.h>
There is no such header in standard C++. use
#include <iostream>
using namespace std ;
instead.
> void main()
main must return an int. see
http://www.research.att.com/~bs/bs_faq2.html#void-main
> when i am running this code it is not taking input of year.why is this happening and how can i solve this problem?
There is some crud left in the input buffer. Make sure that you no not enter more than 39 characters for name, 14 characters for rno and one character for brch.