quick question: why wont this while-loop wait for input?
(ing is a string)
while(ing != "0")
{
cout << "Ingredient name: ";
cin >> ing;
for(int i = 0; i < ing.length(); i++)
{
if(ing[i] == ' ')
ing[i] = '#';
}
fil << ing << ':';
cout << "Quantity: ";
cin >> quant;
fil << quant << ':';
}
it just spamms “ingredient name: quantity: ingredient name: quantity: …” and so on
Not sure what
filis.I think your problem is that you need to flush the stream with a
cin.ignore()at the bottom of the loop (or else do acin.getline()to get your input). Otherwise the newline at the end of the input (when you press enter to submit the input) gets saved for the nextcinwhich is yourcin >> ing. So the newline gets used up there and doesn’t actually ask the user for new input.