0

C++help

I have a small problem in c++ I need a code whose output character string is formed from the characters of the source string with even ordinal numbers. Please help me

3rd Apr 2022, 12:35 PM
Daniel Alexis
28 Answers
+ 3
char A B C D E F index 0 1 2 3 4 5 B, D and F are all in odd indices ... Which is it? odd or even?
3rd Apr 2022, 12:51 PM
Ipang
+ 3
Alright, here's one way to implement it, not in code, though I'm sure you can figure it out Let is_odd = false For each character in text If is_odd Print the character End if Let is_odd = NOT is_odd End For Here <is_odd> initialized with false cause we begin loop from 1st character (index 0 ~ even), and <is_odd> will be inverted on each iteration.
3rd Apr 2022, 1:07 PM
Ipang
+ 3
From index i=1 to str.length, print str[I] with i incrementing by 2=> i+=2 . simple.
3rd Apr 2022, 1:17 PM
Jayakrishna ๐Ÿ‡ฎ๐Ÿ‡ณ
+ 2
Pls post your try ..Daniel Alexis
3rd Apr 2022, 12:49 PM
Jayakrishna ๐Ÿ‡ฎ๐Ÿ‡ณ
+ 2
Sorry for the little inconvenience ๐Ÿ˜…๐Ÿ˜…I'm a little bad at C++ I'm pretty good at Python.Please you could make a very concrete example so that I could understand better.Please.
3rd Apr 2022, 1:16 PM
Daniel Alexis
+ 2
Thx
3rd Apr 2022, 1:47 PM
Daniel Alexis
+ 2
// I hope this link helps you https://code.sololearn.com/cw5UvLs6C3bw // or for (int i=97; i<=122; i++) if (i%2==0) cout<<(char)i;
3rd Apr 2022, 1:52 PM
SoloProg
SoloProg - avatar
+ 2
Thx
3rd Apr 2022, 2:05 PM
Daniel Alexis
+ 2
I will start very soon.Duty is for tomorrow ๐Ÿ˜ญ
3rd Apr 2022, 6:31 PM
Daniel Alexis
+ 1
Can you illustrate with example?
3rd Apr 2022, 12:46 PM
Faisal Issaka
Faisal Issaka - avatar
+ 1
Sorry, Odd
3rd Apr 2022, 12:57 PM
Daniel Alexis
+ 1
Okay so from the illustration above You can use the modulus operator to check if it odd the you just some them up
3rd Apr 2022, 1:08 PM
Faisal Issaka
Faisal Issaka - avatar
+ 1
I will try to figure out how to implement what you are telling me...tomorrow I have several exams of programmation.si I had the code already written, it would have made it easier for me.
3rd Apr 2022, 1:47 PM
Daniel Alexis
+ 1
Loop through the characters of the source string. Check whether the character is even. If so, then print it. if (source_string[i]&1==0) cout << source_string[i];
3rd Apr 2022, 3:35 PM
Brian
Brian - avatar
+ 1
Thank you very much but I don't understand, because C++ is not really my field.
3rd Apr 2022, 3:50 PM
Daniel Alexis
+ 1
Do you have a code already written?
3rd Apr 2022, 3:52 PM
Daniel Alexis
+ 1
Daniel Alexis you might want to start learning C++ from the Sololearn tutorial. There you can learn about the char type, string type, arrays, input, output, loops, and all the syntax you need for this. https://www.sololearn.com/Course/CPlusPlus/?ref=app
3rd Apr 2022, 6:09 PM
Brian
Brian - avatar
+ 1
I managed to display bdf but the teacher tells me that I must indicate abcdef too. Please help me.
4th Apr 2022, 10:03 AM
Daniel Alexis
4th Apr 2022, 10:07 AM
Daniel Alexis
+ 1
Daniel Alexis copy the code and paste in SL playground and save, share link here.. That's helps find easy solution. Do you mean, you needed output is : abcdefg bdf If yes, after 1st loop : print s Like cout<<s<<endl;
4th Apr 2022, 11:04 AM
Jayakrishna ๐Ÿ‡ฎ๐Ÿ‡ณ