T
Tarique
Hello all.
How can i clear the input buffer before i accept a user input?Further
what is the correct way to clear the buffer in case of an *invalid*
input.The following naive program will show up the error.
any help will be greatly appreciated.
#include<iostream>
#include<stdlib.h>
using namespace std;
class Publication
{
protected:
char title[30];
float price;
public:
void getdata(void)
{
cout<<"Title :"<<endl;
gets(title);
cout<<"Price"<<endl;
cin>>price;
}
void putdata(void)
{
cout<<"Title :"<<title<<endl;
cout<<"Price :"<<price<<endl;
}
};
class Bookublic Publication
{
private:
int page_count;
public:
void getdata(void)
{
Publication::getdata();
cout<<"No of pages"<<endl;
cin>>page_count;
}
void putdata(void)
{
Publication:utdata();
cout<<"No Of Pages"<<page_count<<endl;
}
};
class Tapeublic Publication
{
private:
int play_time;
public:
void getdata(void)
{
Publication::getdata();
cout<<"Playtime"<<endl;
}
void putdata(void)
{
Publication:utdata();
cout<<"Play time"<<play_time<<endl;
}
};
int main(void)
{
Book B1;
Tape T1;
int ch;
cout<<"...........B1........."<<endl;
B1.getdata();
B1.putdata();
cout<<"...........T1........."<<endl;
//while (('\n' != (ch = getchar())) && (EOF !=ch));
T1.getdata();
T1.putdata();
return 0;
}
How can i clear the input buffer before i accept a user input?Further
what is the correct way to clear the buffer in case of an *invalid*
input.The following naive program will show up the error.
any help will be greatly appreciated.
#include<iostream>
#include<stdlib.h>
using namespace std;
class Publication
{
protected:
char title[30];
float price;
public:
void getdata(void)
{
cout<<"Title :"<<endl;
gets(title);
cout<<"Price"<<endl;
cin>>price;
}
void putdata(void)
{
cout<<"Title :"<<title<<endl;
cout<<"Price :"<<price<<endl;
}
};
class Bookublic Publication
{
private:
int page_count;
public:
void getdata(void)
{
Publication::getdata();
cout<<"No of pages"<<endl;
cin>>page_count;
}
void putdata(void)
{
Publication:utdata();
cout<<"No Of Pages"<<page_count<<endl;
}
};
class Tapeublic Publication
{
private:
int play_time;
public:
void getdata(void)
{
Publication::getdata();
cout<<"Playtime"<<endl;
}
void putdata(void)
{
Publication:utdata();
cout<<"Play time"<<play_time<<endl;
}
};
int main(void)
{
Book B1;
Tape T1;
int ch;
cout<<"...........B1........."<<endl;
B1.getdata();
B1.putdata();
cout<<"...........T1........."<<endl;
//while (('\n' != (ch = getchar())) && (EOF !=ch));
T1.getdata();
T1.putdata();
return 0;
}