Use a noninteger increment as counter variable - C++ Statement

C++ examples for Statement:for

Description

Use a noninteger increment as counter variable

Demo Code

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()/*  ww  w  .j a  v  a2  s. c  om*/
{
   double x, y;
   cout << "x value      y value\n" << "-------     ---------\n";
   cout << setiosflags(ios::fixed) << setiosflags(ios::showpoint) << setprecision(5);
   for (x = 2.0; x <= 6.0; x = x + 0.5)
   {
      y = 10.0 * pow(x,2.0) + 3.0 * x - 2.0;
      cout << setw(7) <<  x << setw(14) << y << endl;
   }
   return 0;
}

Result


Related Tutorials