hi...i'm trying to improve a simple program that i made...
this is a cash receipt program...
to avoid the program form crashing,i insert a code of cin.fail()
which will determine wether the data type the user entered is correct or not...
if the data type is wrong that the program will tell the user that the data type that she/he entered is wrong..
and then will allow the user to enter the correct data type again..
this program goes well when determine the data type,but the problem is that it is not even give me to enter back the correct data type when i was wrong..
for example,if i enter "dghttsg" when this program asking me for the id of the product which have the data type of int,it will alert me that i were wrong but i'm not be able to enter the value back even if i already put cin>>product.id on my code....
below is the part of the program :
if (cin.fail()){
do{
cout<<"Wrong Data Type of Input!";
cout << "Please Enter the Product ID Again : ";
cin >> product[i].id;//whats wrong here??
}while(cin.fail());
}
cout<<endl;
cout << "Enter the Product Name : ";
cin >> product[i].name;
cout << "Enter the Price For Single Item : ";
cin >> product[i].price;
cout << "Enter The Quantity : ";
cin >> product[i].quantity;
cout<<endl;
cout << "Would You like to enter another product? (Y/N) ";
cin >> answer;
i++;
cout<<endl;
}
}while(answer == 'y' || answer == 'Y');
Thanks for your time.. :)