Hello!
I am writing c++ program on linux.
Whenever I read a char or string, I got problem.
In c, I sove the problem using
if(getchar()=='\n')
in c++, how can I sove that problem?
Here is my program. I cannot do any input for name.
Please help me.
#include<iostream.h>
struct Student
{
int rno;
char name[20];
int cmark;
int osmark;
int javamark;
void setdata()
{
cout<<"\nEnter rno:";
cin>>rno;
cout<<"\nEnter name:";
//if(getchar()=='\n');
cin.getline(name,20);
cout<<"\nEnter mark for c:";
cin>>cmark;
cout<<"\nEnter mark for os:";
cin>>osmark;
cout<<"\nEnter mark for java:" ;
cin>>javamark;
}
void testdata()
{
int fcount=0;
if(cmark<=40)fcount++;
if(osmark<=40)fcount++;
if(javamark<=40)fcount++;
if(fcount>1)
cout<<"\n"<<rno;
}
};
int main()
{
struct Student stu[3];
int i;
for(i=0;i<3;i++)
stu[i].setdata();
cout<<"\nFailed list";
for(i=0;i<3;i++)
stu[i].testdata();
return 0;
}