+ 2

Why we use my variable​ command ??

I can also use cout <<" 10"; for 10 out put

11th May 2017, 8:18 AM
deepak kumar verma
deepak kumar verma - avatar
4 Respuestas
+ 7
you can just cout << "10" but what if instead of 10 you wanted to see the results of 10 times a number which is entered by the user of your program?
11th May 2017, 8:22 AM
jay
jay - avatar
+ 4
I don't know
11th May 2017, 8:24 AM
deepak kumar verma
deepak kumar verma - avatar
+ 2
If a program only has constant numbers, it wouldn't be called a program. It would be more like a document.
11th May 2017, 8:26 AM
Calviղ
Calviղ - avatar
0
You definitely can, and for a simple program like in the example your way might even be better. Variables are really nice if you want them to change later. For example: int moneyInWallet = 0; int deposit = 10; moneyInWallet = moneyInWallet + deposit; cout << moneyInWallet << endl; //moneyInWallet is now 10 variables are also really nice for readability. I don't know about you but numbers are to mathy for me. I'de rather my programs read as close to english as possible. Later edit -> When you're using cout << "10"; you are console logging the ***string*** 10. . . you want to console out the ***integer*** 10. "10"+"10" = 1010 10 + 10 = 20
11th May 2017, 9:48 PM
Thomas W. Smith
Thomas W. Smith - avatar