Not get desired output in c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Not get desired output in c++

#include <iostream> using namespace std; int main() { cout << " c \n"; cout << " + \n"; cout <<" + "; return 0; } Why I am not getting output which is C + + It is question from c++ course lesson 3

11th Mar 2024, 4:23 AM
Om Kharate
Om Kharate - avatar
4 Answers
+ 4
#include <iostream> using namespace std; int main() { cout << "C\n"; cout << "+\n"; cout <<"+"; return 0; } I think you should remove the space and use a capital C.
11th Mar 2024, 4:29 AM
Mafdi
Mafdi - avatar
+ 2
you really don't need all those cout. You can condense it to one line. cout<<"C\n+\n+";
11th Mar 2024, 5:29 AM
Bob_Li
Bob_Li - avatar
0
The issue with your code is that you are using the escape sequence `\n` after the second `" + "`, which is causing the next character to be printed on a new line. Here's the corrected code: #include <iostream> using namespace std; int main() { cout << "C\n"; cout << "+\n"; cout << "+"; return 0; } Now, this should give you the desired output: ``` C + + ```
11th Mar 2024, 8:18 AM
Knight
Knight - avatar
0
here is something to explore. Google 'iomanip setw()' and 'C++ for-each loop' to learn more... #include <iostream> #include <iomanip> using namespace std; int main() { int tab = 10; for(auto c : "PYTHON") cout<<setw(tab)<<c<<'\n'; }
11th Mar 2024, 9:29 AM
Bob_Li
Bob_Li - avatar