- Joined
- Dec 12, 2022
- Messages
- 8
- Reaction score
- 0
The prompt is: "Read a 3-character string from input into variable inString. Declare a Boolean variable noDigits and assign noDigits with true if inString does not contain any digits. Otherwise, assign noDigits with false."
I cannot figure out why my code doesn't work. Any help would be appreciated!
I cannot figure out why my code doesn't work. Any help would be appreciated!
C++:
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main() {
string inString;
getline(cin, inString);
bool noDigits;
if(!(isdigit(inString.at(0) && (!(isdigit(inString.at(1)) {
noDigits = true;
} else {
noDigits = false;
}
if (noDigits) {
cout << "String accepted" << endl;
}
else {
cout << "String not accepted" << endl;
}
return 0;
}