Google
 

Friday, August 20, 2010

Technical Editor for “Ivor Horton’s Beginning Visual C++ 2010″

Technical Editor for “Ivor Horton’s Beginning Visual C++ 2010″

Ivor.Hortons.Beginning.Visual.CPlusPlus.2010-indefinitely Loops issue

Issue: indefinitely loops can’t apply to 1.0 but for 0.6
Page 150:
for(double x = 0.0 ; x != 1.0 ; x += 0.2)        
cout < < x;

Code should be updated as the following:
// Ex3_13.cpp
// Demonstrating nested loops to compute factorials
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
cout.precision(21);
for(double x = 0.0 ; x != 0.6 ; x += 0.2)
//for(double x = 0.0 ; x != 1.0 ; x += 0.2)
{
if( 0.2 == x)
cout << "0.2" << endl;
if( 2 == x)
cout << "2" << endl;
if( 0.4 == x)
cout << "0.4" << endl;
if( 0.6 == x)
cout << "0.6" << endl;
if(0.8 == x)
cout << "0.8" << endl;
if(1.0 == x)
cout << "1.0" << endl;
if(1 == x)
cout << "1" << endl;

cout << fixed << x << endl;
}
return 0;
}