What the wrong in this c++ help me | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 2

What the wrong in this c++ help me

https://code.sololearn.com/cisUhphfxghC/?ref=app

10th Mar 2020, 2:35 PM
Yakout Yasser Yakout Aprahim Allam
Yakout Yasser Yakout Aprahim Allam - avatar
20 Respuestas
+ 5
Try this #include <iostream> using namespace std; int main() { int x; int y; cout <<"enter x\n"; cin >>x; cout <<"enter y\n"; cin >>y; int sum =x+y ; int div =x/y ; int mu =x*y ; cout << sum<<"\n"<<div<<"\n"<<mu<<"\n"; return 0; }
10th Mar 2020, 3:29 PM
Ketul Patel
Ketul Patel - avatar
+ 4
at the end it should be cout << sum << "\n" << div << "\n" << mu << "\n"; You need to seperate the strings from variables with the << operator. I would suggest you not use "\n" but do this instead: cout<<sum<<endl; cout<<div<<endl; cout<<mu<<endl; Generaly it is better to use \n at the end of the strings but try avoiding it because endl looks more clear to the eye. That's my personal opinion
10th Mar 2020, 2:46 PM
xaralampis_
xaralampis_ - avatar
+ 3
Yakout Yasser Yakout Aprahim Allam just remove those \n From line 15. '\n' is used for a line break within the string. No need of '\n' in line 15.
10th Mar 2020, 2:38 PM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 1
Ty
10th Mar 2020, 2:46 PM
Yakout Yasser Yakout Aprahim Allam
Yakout Yasser Yakout Aprahim Allam - avatar
+ 1
But if i want make all anser start from new line what should i do
10th Mar 2020, 2:47 PM
Yakout Yasser Yakout Aprahim Allam
Yakout Yasser Yakout Aprahim Allam - avatar
+ 1
Pls annser
10th Mar 2020, 2:48 PM
Yakout Yasser Yakout Aprahim Allam
Yakout Yasser Yakout Aprahim Allam - avatar
+ 1
If that's what you mean: cout<<"enter x:"<<endl; cin>>x; Though it would be cool if you did that too //That's what you did cout<<"enter x:\n"<<endl; cin>>x;
10th Mar 2020, 2:50 PM
xaralampis_
xaralampis_ - avatar
+ 1
~ swim ~ Yeah that's true but in a program that you have console output with cout, I wouldn't care so much about performance since printing is really slow too
10th Mar 2020, 2:52 PM
xaralampis_
xaralampis_ - avatar
+ 1
Pls write \n in"\n" (double inverted comas )instead of \n.
11th Mar 2020, 10:52 AM
Yash Kumar
Yash Kumar - avatar
+ 1
#include <iostream> using namespace std; int main() { int x, y; // Since both return same type, you can declare them in same row cout << "enter x\n"; cin >> x; cout << "enter y\n"; cin >> y; int sum = x + y; int div = x / y; //Will not really hold the real value of a division if the number is real. It's better to divide and module the rest of the division. Like that (mod = x % y; int mu = x * y; cout << sum << endl << div << endl << mu << endl; // \n is mostly used when you're printing a string cause quote are already open, otherwise endl do the same without having to open quote or print string. return 0; } I hope I helped out, not my native language so sorry if I have made bunch of errors. I am as well still new with C++ programming so I might be wrong.
11th Mar 2020, 1:31 PM
Overflow
Overflow - avatar
+ 1
Where u wrote cout in line 14 u missed double quotes in \n
11th Mar 2020, 3:22 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
Ty it work #include <iostream> using namespace std; int main() { int x; int y; cout <<"enter x\n"; cin >>x; cout <<"enter y\n"; cin >>y; int sum =x+y ; int div =x/y ; int mu =x*y ; cout << sum<<"\n"<<div<<"\n"<<mu<<"\n"; return 0; }
11th Mar 2020, 5:09 PM
Yakout Yasser Yakout Aprahim Allam
Yakout Yasser Yakout Aprahim Allam - avatar
+ 1
do it as that is executing #include <iostream> using namespace std; int main() { int x; int y; int sum,div,mu; cout <<"enter x\n"; cin >>x; cout <<"enter y\n"; cin >>y; sum =x+y ; div =x/y ; mu =x*y ; cout << sum<<endl<<div<<endl<<mu; return 0; }
11th Mar 2020, 5:23 PM
Mohammad Waqas
Mohammad Waqas - avatar
+ 1
the cout line
11th Mar 2020, 6:31 PM
John
John - avatar
+ 1
Use instead of \n is <<"\n"
11th Mar 2020, 6:46 PM
deepak
deepak - avatar
+ 1
\n is come in double quoted or you yse endl instead of \n
11th Mar 2020, 7:10 PM
Mohammad Waqas
Mohammad Waqas - avatar
+ 1
Yakout Yasser Yakout Aprahim Allam Line number 7 and 9: hit space before typing \n Line number 14 is all messed up too. Use '\n' instead of just \n and separate it with <<. Here is the code all fixed, refer to it and learn from your mistakes. Good luck. https://code.sololearn.com/c8SZ5WCyw862/?ref=app
11th Mar 2020, 10:32 PM
Ahmed Hushaan
+ 1
https://code.sololearn.com/c02MU9D9v6Yl/?ref=app
12th Mar 2020, 8:35 AM
Ник Я
Ник Я - avatar
12th Mar 2020, 10:53 AM
Phan Thành Công
Phan Thành Công - avatar
+ 1
Line 14 should be cout << sum <<'\n'<<div<< '\n'<<mu <<'\n';
12th Mar 2020, 12:53 PM
Max Mykhasiuta
Max Mykhasiuta - avatar