error with getchar

the programe is not wOrking prOpertly with getchar() is wOrking with gt ch,getche and cin bt nOt with getchar.....:(
here iss the prOg cOde.....

#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

float rad;
char tr; // character tr fOr getting char 'y' if u wAnt tO caLcuLatE othEr chaLLan


cout<<"plz give thE rAdius fOr caLcuLating circumfErenc : ";
cout<<"thE circumfErncE of circL = "<<circum(rad);//functOn caLL
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
while(tr == 'y');


float circum(float rad) //functiOn definAtOn


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...
Add this statement before your getchar call:

while (cin.readsome(&tr, 1) != 0);
	  tr =getchar(); 

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.
Topic archived. No new replies allowed.