0

Requesting User To Input "Sum of two numbers"

#include <iostream> using namespace std; int main() { int a, b; int sum; cout << "Enter a number \n"; cin >> a; cout << "Enter another number \n"; cin >> b; sum = a + b; cout << "Sum is: " << sum <<endl; return 0; } My question is why /n can not be replaced at <<endl Any help please. <<ednl and /n are same.

5th Nov 2017, 6:45 AM
Robin
Robin - avatar
3 Answers
0
thanks
7th Nov 2017, 9:21 AM
Robin
Robin - avatar
+ 10
You can write like this: cout << "Sum is: " << sum << "\n";
5th Nov 2017, 7:01 AM
Shamima Yasmin
Shamima Yasmin - avatar
+ 1
\n is used (as you did) in a string expression. like shamima did in his/her example too, within quotes. endl; is used out of string expressions (without quotes).
5th Nov 2017, 12:11 PM
storm
storm - avatar