Can you identify if Cody's name is spelled right? If so, then make a program that accepts four one-letter strings separated by space and print "Correct" if the inputted strings, combined in order, spell the name Cody correctly. If not, print "Wrong". It doesn't matter if it's in uppercase or lowercase, as long as it's spelled correctly, it's considered correct.
Now, will you take on this task?
input
1.First Character
2.Second Character
3.Third Character
4.Fourth Character
#include <iostream>
#include <cctype>
using namespace std;
int main() {
char name[4];
char* cody ="cody";
for (int i=0; i<4; i++ ) {
cin >> name[i];
}
bool correct = true;
for (int i=0; i<4; i++) {
if (tolower(name[i]) != cody[i]) {
correct = false;
break;
}
}
if (correct) {
cout << "Correct";
}
else {
cout << "Wrong";
}
return 0;
}
Comments
Leave a comment