You are here:

C++/logical problem in c++

Advertisement


Question
when 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.  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


vijayan

Expertise

my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.

Experience

about 15 years or so

Education/Credentials
post graduate engineer

©2016 About.com. All rights reserved.