+ 1
How to solve this?
https://code.sololearn.com/cv6m4jPvD6bH/?ref=app so the code above suppose to print your name after you entered it (I know genius đ), I want to print just the letters in ODD places from the entered name (ex:if you enter: Jhon , it will print: h , n). How can I do that?
4 Answers
+ 5
#include <iostream>
using namespace std;
int main() {
std::string name;
cout << "Enter your name" << endl;
cin >> name;
int size = name.size()
for(int i = 0; i < size; i++) {
if(i % 2 != 0) {
cout << name[i] << endl;
}
}
}
+ 2
@Cool Codin
I think you should use name.length() or name.size() instead of sizeof(name)/sizeof(name[0]); . It won't work as expected in all cases... After all, sizeof doesn't just return the size of the string times size of a char (1).
https://drive.google.com/folderview?id=1psMK0Q-orarN6pRroX33YcxIMGQN3uak
+ 1
THX!
+ 1
thx, I'll try that.