the programe is not wOrking prOpertly with getchar() only......it is wOrking with gt ch,getche and cin bt nOt with getchar.....:(
here iss the prOg cOde.....
#include<iostream>
#include<conio.h> //header file incLuded tO include get character getch()
#define pi 3.1415926 //to definE the vaLue of a cOnstAnt pi
using namespace std;
float circum(float); //prOtotypE
main()
{
float rad;
char tr; // character tr fOr getting char 'y' if u wAnt tO caLcuLatE othEr chaLLan
do
{
cout<<"plz give thE rAdius fOr caLcuLating circumfErenc : ";
cin>>rad;
cout<<"thE circumfErncE of circL = "<<circum(rad);//functOn caLL
cout<<endl;
cout<<"u wAnt tO calcuLate circumfErencE agAin(y/n)";
//cin>>tr; //use cin tO prOmpt usEr or getch() or getche()
//tr =getch(); //do not show the character enterd
//tr =getche(); //dispLay the character
tr =getchar(); //enter the char untiL entEr is prEsed nOt wOrking right nOw
cout<<"\n";
}
while(tr == 'y');
What do u mean not working ?
U should stay consistent with ur functions. If u'r using cin then just use cin again...the performance loss is negligible.
Perhaps try calling cin.flush() or cin.clear() after cin>>rad; as there may still be chars in the buffer which getchar() is grabbing...
Is working fine for me. The readsome command is the key here; I would look that up. Typically there is a line feed or some other value stored in the char which is tricking the buffer into thinking a character has already been fetched.