Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > BOOK: Ivor Horton's Beginning Visual C++ 2005
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Ivor Horton's Beginning Visual C++ 2005
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2005 by Ivor Horton; ISBN: 9780764571978
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2005 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 February 1st, 2007, 04:38 PM
Authorized User
Points: 174, Level: 3
Points: 174, Level: 3 Points: 174, Level: 3 Points: 174, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2006
Location: , , .
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default weird problem with Ch 9 example

in the section on using for loops with a continue statement, pgs 139-140, I get a different result for the variable "product" depending on whether I compile it and run it from a command prompt, or whether I press ctrl+F5 in visual studio (running without debugging). This happens when I continually enter the number 0 for the cin value variable. (ten 0's)

running at the command prompt, the value for "product" at the end is 1, as it is initialized in the program

With ctrl-F5, it is 0.

Anyone know what this is? Not that it's important in the big scheme of things, but I'd like to know why there is an inconsistency.

thanks in advance

and here's the code for cut and paste. Also, you might try uncommenting my comments lines, building, and then running from the DOS prompt - for some reasons, the lines, when uncommented, make the value change too.

Code:
// for loop
#include <iostream>
#include <iomanip>

using std::endl;
using std::cout;
using std::cin;
using std::setw;

int main()
    {
        int i = 0, value = 0, product=1;
        for (i=1; i<=10; i++)
            {
                //cout << "product now equals " << product << endl;
                //cout << "value now equals " << value << endl;
                //cout << "product * value now equals " << (product *= value) << endl;
                cout << "Enter an integer: ";
                cin >> value;

                if (value == 0)
                    continue;

                product *= value;
            }
        cout << "Product (ignoring zeros): " << product << endl;

        return 0;
    }
Sincerely,
Brian
__________________
Sincerely,
Brian
  #2 (permalink)  
Old February 2nd, 2007, 02:06 AM
Authorized User
 
Join Date: May 2006
Location: Iver, Bucks., United Kingdom.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Not something I can check for you...

Since applying the VS 2005 update, under 'start debugging' the console window comes up to take in data, e.g. your 10 zero's, but then displays the result (I assume) and closes instantly/ automatically.

If I then run it in 'start without debugging' the console window does not close until it has displayed the result and displays 'press any key to continue..."

Nick

 


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
Very WEIRD Mail Problem Lee Dumond BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 January 16th, 2008 02:11 PM
weird problem! Please Help johnjohn Classic ASP Databases 5 December 21st, 2004 10:27 AM
Weird Access Problem MattyJ Access 2 October 1st, 2004 03:10 PM
weird Oracle problem! pankaj_daga Oracle 2 July 12th, 2004 10:33 PM



All times are GMT -4. The time now is 09:20 PM.


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