Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 1st, 2007, 04:38 PM
Authorized User
 
Join Date: Dec 2006
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
 
Old February 2nd, 2007, 02:06 AM
Authorized User
 
Join Date: May 2006
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






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 02:10 PM
weird Oracle problem! pankaj_daga Oracle 2 July 12th, 2004 09:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.