0
why wont this work
#include <iostream> using namespace std; int main() { try { string name; cin >> name; if (name >=20 && name >=4) { cout << "Valid" << endl; throw 99; } } catch (int x) { cout<<"Invalid"<<endl; } return 0; }
4 Respostas
+ 2
Mando
Name is string and 20 is a number then how you can compare?
get size of name then compare.
if size >= 20 then how it can be >=4
size should be <=20 && >= 4
+ 1
AJ then why doesnt this work then #include <iostream>
using namespace std;
int main()
{
try {
int name;
cin >> name;
if (name<=20 && name >= 4) {
cout << "Valid" << endl;
}
else
cout << "Invalid" << endl;
}
return 0;
}
0
Mando
Name is string not int.
Mando can't be 4 or 20 it's a string
Mando >= 4 //wrong comparison
5 >= 4 //right comparison
First code is right but you need to compare size of string with 20 and 4
Notes: Read my first answer again
0
AJ
#include <iostream>
using namespace std;
int main() {
string name;
cin >> name;
try {
string str = name ;
str.size();
if (str <=20 && >= 4 ){
cout << "Valid" << endl;
}
else
cout << "Invalid"<< endl;
}
catch(int x) {
}
return 0;
}
I dont understand i followed the steps and it still doesnt work