Exception Handling | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Exception Handling

anyone could tell me what I am making wrong with the code, because can't pass all of it, just pass 3 of the 4 question . You are making a program to manage user names. A valid username needs to be minimum 4, maximum 20 characters long. Create a program to take a string as input, check its length and output "Valid" if the name is valid, or "Invalid", if it is not. https://code.sololearn.com/ca15A17a7a77

10th Jun 2021, 5:05 AM
JRAMAHES
JRAMAHES - avatar
5 Answers
+ 3
[ "JRamoneMH " ] :: There will be >= 4 and <= 20 if(name.size() >= 4 && name.size() <= 20 ){
10th Jun 2021, 5:12 AM
A͢J
A͢J - avatar
+ 2
#include <iostream> using namespace std; int main() { string name; cin >> name; try { if(name.size() >= 4 && name.size() <= 20 ){ cout << "Valid" << endl;; }else{ throw "Invalid"; } } catch(char const* x) { cout<< x; } return 0; } //Good Luck
20th Dec 2022, 3:11 PM
James Joshua
James Joshua - avatar
+ 1
thank you Ajanant, I definitely forgot to use my knowledge about the operator. I appreciate it.
10th Jun 2021, 5:21 AM
JRAMAHES
JRAMAHES - avatar
0
#include <iostream> using namespace std; int main() { string name; cin >> name; try { if(name.size() >= 4 && name.size() <= 20 ){ cout << "Valid" << endl;; }else{ throw "Invalid"; } } catch(char const* x) { cout<< x; } return 0; } Good Luck
26th Jan 2022, 5:44 AM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
0
I still dont get why 3rd test case is not passing
20th Oct 2023, 6:34 PM
Nitish Kumar
Nitish Kumar - avatar