Проверка ввода пользователя. Если введен неправильный ввод, он становится точным. Если введен правильный ввод, он должен быть снова введен для регистрации. Помогите?C++ If/Else loop problems
int deposit;
cout << "How much do you want to deposit?" << endl;
cin >> deposit;
if (!(cin >> deposit)) { // If the input is not equal to the data type of
// deposit
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Invalid Input" << endl;
} else {
while (infile >> u >> p >> b) {
if (checkUser == u) {
int newBalance;
cout << "Your amount of $" << deposit << " has been added to your account"
<< endl;
int fileBalance;
stringstream convert(b); // object from the class stringstream
convert >> fileBalance; // the objects has the value of B and
newBalance = fileBalance + deposit;
outfile << checkUser << ' ' << checkPass << ' ' << newBalance << endl;
} else {
outfile << u << ' ' << p << ' ' << b << endl;
}
}
}
Вы дважды вызываете депозит cin >>, поэтому вы ожидаете, что нужно ввести два номера. Кроме того, блок else не имеет закрывающей скобки. –
@Holget Schmitz Спасибо! Ошибка новичка. – cparks10