- 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
5 Respostas
+ 3
[ "JRamoneMH " ] ::
There will be >= 4 and <= 20
if(name.size() >= 4 && name.size() <= 20 ){
+ 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
+ 1
thank you Ajanant, I definitely forgot to use my knowledge about the operator.
I appreciate it.
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
0
I still dont get why 3rd test case is not passing