do
{
system("cls");
cout<<"Enter Item Name:"<<endl;
cin.ignore();
cin.getline(item_name,size);
cout<<item_name<<endl;
cout<<"Enter Item Price:"<<endl;
cin>>item_price;
cout<<" Do You Want To Add More Item..?\nPress Y/N."<<endl;
char c;
c=getche();
}while(c=='y'||c=='Y');
this is the pace of code , actually i am using this in my project, i cannot remove cin.ignore because i have to get input from user unless user press any other character rather then y
You know the answer to your question in the title. The call
cin.ignore();
reads the next character from cin
and discards it.
The real question that you are grappling with, I think, is: how do you terminate the loop?
That's simple enough. Don't compare just one character. Compare the entire line.
do
{
system("cls");
cout << "Enter Item Name:"<<endl;
cin.getline(item_name, size);
cout << item_name << endl;
cout << "Enter Item Price:" << endl;
cin >> item_price;
cout << "Do You Want To Add More Item..?\nPress Y/N." << endl;
std::string ans;
getline(cin, ans);
} while (ans == "y" || ans == "Y");
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments