+ 2
What the wrong in this c++ help me
22 Antworten
+ 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;
}
+ 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
+ 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.
+ 1
Ty
+ 1
But if i want make all anser start from new line what should i do
+ 1
Pls annser
+ 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;
+ 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
+ 1
Pls write \n in"\n" (double inverted comas )instead of \n.
+ 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.
+ 1
Where u wrote cout in line 14 u missed double quotes in \n
+ 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;
}
+ 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;
}
+ 1
the cout line
+ 1
Use instead of \n is <<"\n"
+ 1
\n is come in double quoted or you yse endl instead of \n
+ 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
+ 1
https://code.sololearn.com/c02MU9D9v6Yl/?ref=app
+ 1
+ 1
Line 14 should be
cout << sum <<'\n'<<div<< '\n'<<mu <<'\n';