Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 4.0 aka C# 2010 > BOOK: Beginning Visual C# 2010
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Visual C# 2010
This is the forum to discuss the Wrox book Beginning Visual C# 2010 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, ; ISBN: 9780470502266
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# 2010 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 18th, 2010, 10:19 PM
Registered User
 
Join Date: May 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 3 Exercise 4 Solution

in the appendix, the solution to this exercise is:

resultVar += ((var1 * var2) << (var4 / var5));

I could not find an explanation for "<<"

Can someone please explain?

thanks
kb
  #2 (permalink)  
Old May 19th, 2010, 12:33 AM
Registered User
 
Join Date: May 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Question


okay...
found the answer (sort of) here:
http://msdn.microsoft.com/en-us/libr...(v=VS.71).aspx

which leaves me more confused than ever as to why that is the answer to Chapter 3 Exercise 4 Solution
  #3 (permalink)  
Old June 22nd, 2010, 10:38 PM
Registered User
 
Join Date: Jun 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Wink Typo

I believe that's just a typo and the correct answer is:

resultVar += (((var1 * var2) + var3) % (var4 / var5));
  #4 (permalink)  
Old July 15th, 2010, 04:22 AM
Authorized User
 
Join Date: Mar 2010
Posts: 14
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes it is a typo error.
And the correct answer is:

resultVar += ((var1 * var2) + ((var3 % var4) / var5));

*, % and / have the same priority and in that case it is the leftmost operator that operates first.
  #5 (permalink)  
Old July 15th, 2010, 09:20 PM
Authorized User
 
Join Date: Jun 2010
Posts: 27
Thanks: 8
Thanked 0 Times in 0 Posts
Default Operator Priority

According to the book:
* has first priority
/ has second and
% has third
page 51 of Beginning Visual C# 2010

So the corrct answer should be:
resultVar += ((var1 * var2) + (var3 % (var4 / var5)));

Tariq
  #6 (permalink)  
Old July 16th, 2010, 05:24 AM
Authorized User
 
Join Date: Mar 2010
Posts: 14
Thanks: 0
Thanked 1 Time in 1 Post
Default

No tariq it is not the right answer :

*, / and % have the same priority.

The order displayed in the book or in any website doesn't mean anything.
what I mean is : it is the same whether they write
*, /, %
or
/, *, %

What only matters is the rank (Higher to Lowest)


Try it out on Visual!
  #7 (permalink)  
Old July 16th, 2010, 07:57 AM
Authorized User
 
Join Date: Jun 2010
Posts: 27
Thanks: 8
Thanked 0 Times in 0 Posts
Default Thanks

Thanks for the clarification:
What you are saying is that which ever operator comes first out of */and % the calculation will start from there:

Am i right?

For example in this case:
resultVar += (var1 * var2) + (var3 % var4) / var5;

Please correct me if i am on the wrong track.

Tariq
  #8 (permalink)  
Old July 16th, 2010, 08:27 AM
Authorized User
 
Join Date: Mar 2010
Posts: 14
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes you got it!

That's exactly it

So in your example, the processing will be performed in this order:
*
%
/
+
+=

That is only if you write it without brackets, I mean like that:
resultVar += var1 * var2 + var3 % var4 / var5;

If you use brackets like for example: resultVar += var1 * (var2 + var3) % var4 / var5;
The order will be:
+
*
%
/
+=

Let me know if you understand my explanation (as English is not my first language).

Bon_chan

Last edited by bon_chan; July 16th, 2010 at 08:34 AM.
  #9 (permalink)  
Old July 16th, 2010, 08:13 PM
Authorized User
 
Join Date: Jun 2010
Posts: 27
Thanks: 8
Thanked 0 Times in 0 Posts
Default That is perfect:

Thanks for explaining.

Hope to c u in some other discussion.

Regards
Tariq
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 3 - Exercise 4 - Solution gives no output Cryotic BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 2 April 19th, 2010 08:57 AM
Chapter 13 Exercise 3 solution firblazer BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 April 19th, 2008 07:16 AM
Solution to exercise 7, Chapter 2 Nick Y BOOK: Ivor Horton's Beginning Visual C++ 2005 0 May 28th, 2006 04:28 AM
exercise solution uddessjava Java Basics 1 December 29th, 2005 03:57 AM
Exercise Solution jgrat BOOK: Beginning Access VBA 3 October 18th, 2004 04:13 PM



All times are GMT -4. The time now is 10:16 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.