- #1
needOfHelpCMath
- 72
- 0
Replace any space ' ' by '_' in 2-character string passCode. If no space exists, the program should not print anything. Sample output for the given program:
1_
Testing: "1 "
Your output: 1_
✖ Testing: "a1"
Expected output: a1
Your output: 1a1
1_
Code:
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main() {
string passCode;
passCode = "1 ";
if (isspace(passCode.at(1))) {
passCode = passCode.at(0);
passCode = "_";
}
cout << "1";
cout << passCode << endl;
return 0;
}
Testing: "1 "
Your output: 1_
✖ Testing: "a1"
Expected output: a1
Your output: 1a1
Last edited by a moderator: