how can i convert the while loop into a for loop?
string input;
cin >> input;
cout << endl;
int count = 0;
int size = input.size();
if(input.size() == 6) {
while(size > 0) {
if(count < 3) {
if((input.at(count) >= 'A' && input.at(count) <= 'Z') || (input.at(count) >= 'a' && input.at(count) <= 'z')) {
count++;
}
else {
cout << "error: letter expected at position " << count + 1;
return 0;
}
}
else if(input.at(count) >= '0' && input.at(count) <= '9') {
count++;
}
else {
cout << "error: digit expected at position " << count + 1;
return 0 ;
}
size--;
}
}
CODE
string input;
cin >> input;
cout << endl;
int count = 0;
int size = input.size();
if(input.size() == 6) {
for (int i=size; i > 0; i--) {
if(count < 3) {
if((input.at(count) >= 'A' && input.at(count) <= 'Z') || (input.at(count) >= 'a' && input.at(count) <= 'z')) {
count++;
}
else {
cout << "error: letter expected at position " << count + 1;
return 0;
}
}
else if(input.at(count) >= '0' && input.at(count) <= '9') {
count++;
}
else {
cout << "error: digit expected at position " << count + 1;
return 0 ;
}
}
}
}
Get Answers For Free
Most questions answered within 1 hours.