Validated user input in C++<\/span><\/p>\n For this mastery, I found \u00a0a super useful video that taught me how to make a validation for a user input<\/span><\/p>\n Here is also an example code with a validation user input code:<\/span><\/p>\n \u00a0<\/p>\n \u00a0<\/p>\n Credits:<\/span><\/p>\n <\/a>https:\/ #TC<\/a>1017 #Mastery<\/a>27<\/span><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":" Validated user input in C++<\/span><\/p>\n For this mastery, I found a super useful video that taught me how to make a validation for a user input<\/span><\/p>\n Here is also an example code with a validation user input code:<\/span><\/p>\n <\/p>\n <\/p>\n Credits:<\/span><\/p>\n <\/a>https:\/\/www.youtube.com\/watch?v=YIX7UhIKEIk<\/a><\/span><\/span><\/p>\n#include<\/a>
#include<\/a> <\/dfn>\n#include<\/a> <\/dfn>\n\nint<\/var> main(){\n bool<\/var> valid = false<\/var>;\n int<\/var> input;\n while<\/var>(!valid){\n if<\/var>(std::cin>>input){\/\/this checks whether an integer was entered<\/cite>\n if<\/var>(input 0) valid = true<\/var>;\/\/then we have to see if this integer is in range<\/cite>\n }else<\/var> std::cin.clear();\/\/some cleaning up<\/cite>\n\t\t\n std::cin.ignore(std::numeric_limits::max(), 'n'<\/kbd>);\/\/empty input stream<\/cite>\n\n if<\/var>(!valid) std::cout \"this input is not validn\";\n }\n std::cout \" is between 1 and 5n\";\n std::cin.get();\n return<\/var> 0;\n}<\/code><\/pre>\n