On Sat, 28 Mar 2020 06:53:26 -0700 (PDT), Kev P <
nivpa...@gmail.com>
wrote:
>I'm using teach yourself C++ in 24hours.
>In chapter 4 I try pre & post fix operators, but get different results to book, but my own little test prog seems to work?
>I'm using: Microsoft Visual Studio Community 2019 (2)
>
> #include <iostream>
> int main()
> {
> int myAge = 39; // initialize two integers
> int yourAge = 39;
> std::cout << myAge << "\n";
> std::cout << yourAge << "\n\n";
> myAge++; // postfix increment
> ++yourAge; // prefix increment
> std::cout << myAge << "\n";
> std::cout << yourAge << "\n\n";
> std::cout << myAge++ << "\n";
> std::cout << ++yourAge << "\n\n";
> std::cout << myAge << "\n";
> std::cout << yourAge << "\n\n";
> return 0;
> }
>Book says this should print as follows (text removed, just values shown):
Since there is no text in any of your output statements, this is not
the code the book uses.
>39 39
>40 40
>40 41
>41 41
>
>But I get:
>39 39
>40 39
>40 40
>41 40
Show us the actual code you used from the book
>
>However, my own cut down version below gives correct(?) answer to book, weird!
>
>#include <iostream>
>int main()
>{
> int a = 39;
> int b = 39;
> std::cout << a << " " << b << "\n";
> a++;
> ++b;
> std::cout << a << " ";
> std::cout << b << "\n\n";
> std::cout << a++ << " ";
> std::cout << ++b << "\n\n";
> std::cout << a << " ";
> std::cout << b << "\n\n";
> return 0;
>}
>39 39
>40 40
>40 41
>41 41
>
>I can't see any difference other than the cout formatting, what am I missing?
When you show us the exact ode you used (don't retype it, use cut and
paste), we will be able to tell you.
--
Remove del for email