A question regarding input validation | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

A question regarding input validation

Lets say if i wanted a c++ program to take an input form user the input can only be a string or a space from user and gives error for integers and characters and retakes the input.How do i do this? void validateString(string str) { cin>>str; for (int i = 0; i<str.length(); i++) { if ((str[i] >= 65 && str[i] <= 90) || (str[i] >= 97 && str[i] <= 122) || str[i] == 32) /*Every caharcter in string is read in form of array of decimal numbers. Thus we check between upper and lower limits for valid input on each character of entered string*/ { break; cout<<"Correct input!"<<endl; } else { cout<<"Please input letters and spaces only"<<endl; validateString(str); } } } this is a function i made which needs some corrections for this validation.any help will be appreciated..

7th Jan 2021, 2:36 PM
Dex
Dex - avatar
0 ответов