HELP ME OUT PLEASE


#1

#include
#include
#include

using namespace std;

class HOTEL
{
int Rno,NOD;
char Name[30];
double Tariff;
double CALC()
{
float temp=NODTariff;
if(temp>10000)
return(1.05
temp);
return temp;
}
public:
void Checkin()
{
cout<<"\nEnter room No. - \n";
cin>>Rno;
printf("\nEnter the Customer Name - \n");
gets(Name);
cout<<"\nEnter the room charges per day - \n";
cin>>Tariff;
cout<<"\nEnter the No. of Days stayed by the customer - \n";
cin>>NOD;
}
void Checkout()
{
cout<<"Room No. - "<<Rno<<endl;
printf("Customer Name - ");
puts(Name);
cout<<"Room Charges per day - "<<Tariff<<endl;
cout<<"No. of Days stayed - "<<NOD<<endl;

		cout<<"Total charges of the customer - "<<CALC()<<endl;
		
	}

};
int main()

{
HOTEL H;
H.Checkin();
H.Checkout();

return 0;
}

I’m not able to enter the customer name ,other than that the whole program is running fine. please suggest corrections and reason.


#2

There is already new line character ‘\n’ present in buffer. And gets() stops taking input when ‘\n’ is occurred in input. That’s why you are not able to enter any input.

For solving this issue add only one line above gets()

getchar();

There is no need to store character anywhere.

It will consume that new line character present in buffer and gets() will work as intended.

You should read more buffer on stack over flow.

Upvote if it helped. It motivates me to write more :):grin: