+ 5

[Solved]C++ practice problem error

I'm learning c++ and there is a practice code problem. I have solved it and it's giving the correct output still it is saying that the output is wrong(case) The task is to print the following poem in this way *Each statement on new line* Roses are red Violets are blue I love C++ And you will like it too! This is the code: #include <iostream> using namespace std; int main() { //modify given statement cout << "Roses are red\n"; cout << "Violets are blue\n"; cout << "I love C++\n"; cout << "And you will like it too!"; return 0; } My output: Roses are red Violets are blue I love C++ And you will like it too! Expected output: Roses are red Violets are blue I love C++ And you will like it too! Both are same ,still it is not passing the case

4th Sep 2020, 2:28 PM
OfcourseitsRohit
OfcourseitsRohit - avatar
6 Answers
+ 7
Try this may be it will work can you send me link of problem . #include <iostream> using namespace std; int main() { //modify given statement cout << "Roses are red\nViolets are blue\nI love C++\nAnd you will like it too!"; return 0; }
4th Sep 2020, 3:46 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 5
It should work. Maybe it was expecting a newline at the end of "And you will like it too". Try that. Then check if the case of the expected output and your output match. Maybe link the problem here?
4th Sep 2020, 2:43 PM
XXX
XXX - avatar
+ 5
XXX I tried that too ,but it's not working
4th Sep 2020, 2:46 PM
OfcourseitsRohit
OfcourseitsRohit - avatar
+ 5
Daljeet Singh yeah correct. Also add space to the 1st statement cout <<" Roses are red\n"; This Worked for me😊thanks
4th Sep 2020, 3:45 PM
OfcourseitsRohit
OfcourseitsRohit - avatar
+ 4
àœžÄ±ÉŹÄ±Æ™Ä… É±Ä±Ê‚É§àœžÄ… yeah I tried that too but it didn't work. Actually there is a space before each statement. The problem question itself has the wrong output. Anyways I reported it to Sololearn Thanks 😊
4th Sep 2020, 3:49 PM
OfcourseitsRohit
OfcourseitsRohit - avatar
+ 3
Well expected output somehow matches this : Your modified code from above //modify given statement cout << "Roses are red\n"; cout << " Violets are blue\n"; cout << " I love C++\n"; cout << " And you will like it too!"; Mind the single wspace :) Compare with org text from problem to see 😉
4th Sep 2020, 3:33 PM
Daljeet Singh
Daljeet Singh - avatar