this is my program

//
//        custorderscf2.cpp
//
#include <cstdlib>     // student ...... Jones, Patricia
#include <iostream>    // section ...... MW    row .... 4
#include <fstream>     // due date ..... xx/xx/xx
#include <iomanip>     // refer to ..... Gaddis Ch3

void     SetPrecision(int);            // procedure prototype
using    namespace  std;               // avoid std::cin >> ...

         /* declare global data elements */
         int        ordnum;            // input variables
         string     partnum;           //
         int        quantity;          //
         double     price;             //

void     readinput  (void);            //
         ifstream   infile;            // declare file object

int      main      (void)              // main function header
{                                      // begin block

         int       oldordnum;          // old order number
         double    de1extprice;        // detail line ext price
         double    cf1extprice;        // order total
         double    cf2extprice;        // report total

         /* begin procedural code */
         SetPrecision(2);                // set floating points
         cf2extprice = 0;                             // clear report total
         infile.open("custorders.bdl");                             // open input file

         /* test for successful open */
         if(!infile)
         {
             cout << "Input file open error!";
             exit(-1);                 // error pgm stop
         }

         /* print column headers       */
         cout << setw(10) << "ORD NUM"
              << setw(10) << "PARTNUM"
              << setw(10) << "QUANTITY"
              << setw(10) << "PRICE"
              << setw(12) << "EXT PRICE" << "\n\n";

         /* begin processing loop      */
         readinput();                     // read first record
         oldordnum = ordnum;                              // save the control field
         while(ordnum != 99999);           // test for more data
         {
                                                              
 cf1extprice = 0;                         // clear order total
              while(ordnum == oldordnum)  // same group ?
              {
         
                  cout << setw(10) << ordnum                                      // detail calc
                       << setw(10) << partnum                                     // level one calc
                       << setw(10) << quantity                                      // print detail
                       << setw(10) << price;
                  de1extprice = quantity * price;                      //
                  cout << setw(12) << de1extprice << endl;
                                                                               //
                 cf1extprice = cf1extprice + de1extprice;                                          //
                                                           //
                  readinput();            // read next record
               }
               cout << endl;
               cout << setw(52) << cf1extprice << "\n\n";  // order total
               cf2extprice = cf2extprice + cf1extprice;    // level two calc
               oldordnum = ordnum;        // save the control field
         }                                //
         cout << endl;
         cout << setw(52) << cf2extprice;                                         // print report total
         
         /* close file and stop run    */
         cout << endl;
         infile.close();               // close file
         return(0);                    // int return to o/s
}                                      // end main block 
               
void     readinput (void)
{
         infile >> ordnum >> partnum >> quantity >> price;
         if (infile.eof())
             ordnum = 99999;
         return;
}
                                                                                 
void     SetPrecision(int pDecPlaces)  // procedure header
{
         cout.setf(ios::right);        // right-justified
         cout.setf(ios::fixed);
         cout.setf(ios::showpoint);
         cout.precision(pDecPlaces);
         return;                       // return to caller
}

and the text is

21608 AT94 11 21.95
21608 KL62 2 329.95
21610 DR93 1 495.00
21610 DW11 1 399.99
21613 KL62 4 329.95
21613 AT94 2 21.95
21613 FD29 1 159.95
21614 AT94 10 21.95
21614 KT03 2 595.00
21617 BV06 2 794.95
21617 CD51 4 150.00
21619 DR93 3 495.00
21619 KV29 2 1290.00

i dont know y it runs into infinite loop
i guess the problem is on while (ordnum != 99999)
or readinput ()
and i want to keep using while loop and
if (infile.eof())

Look at your while loop: you closed it before it started: while(ordnum != 99999); .
Just remove the semicolon right after the while(ordnum != 99999) and everything should be fine ;)

while(ordnum != 99999);

if you put a semi colon at the end of while loop that means the loop doesnt have ne statements incorporated in them .

while(ordnum != 99999);

if you put a semi colon at the end of while loop that means the loop doesnt have ne statements incorporated in them .

Nice catch.

Nice catch.

No it's not. He just posted the exact same thing as 'unbeatable0' posted 10 hours earlier, so I wouldn't call it 'a nice catch' at all. :icon_wink:

am i stupid?
thanks for everyone's replying
especislly unbeatable0

This article has been dead for over six months. Start a new discussion instead.