From d3a0da956800cea2ede2f37c3638fe8146751361 Mon Sep 17 00:00:00 2001 From: maulikaluthra <56387512+maulikaluthra@users.noreply.github.com> Date: Tue, 20 Oct 2020 18:22:14 +0530 Subject: [PATCH] Update ex1_09.cpp Using namespace std --- ch01/ex1_09.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ch01/ex1_09.cpp b/ch01/ex1_09.cpp index 5279e135..f05dc340 100644 --- a/ch01/ex1_09.cpp +++ b/ch01/ex1_09.cpp @@ -2,17 +2,24 @@ #include +using namespace std; + +//“using namespace std” means we use the namespace named std. “std” is an abbreviation for standard. +//If we don’t want to use this line of code, we can use the things in this namespace like this. std::cout, std::endl. +//If this namespace is not used, then computer finds for the cout, cin and endl etc.. Computer cannot identify those and therefore it throws errors. + + int main() { int sum = 0, val = 50; while (val <= 100) { - sum += val; - ++val; + sum += val; //shorthand for sum=sum+val + ++val; //increments the value of val by 1. } - std::cout << "the sum is: " << sum << std::endl; + cout << "The sum is: " << sum << endl; return 0; } -// output: the sum is: 3825 +// output: The sum is: 3825