| | |
c++ problem need help pls
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2009
Posts: 2
Reputation:
Solved Threads: 0
this is my program
and the text is
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())
C++ Syntax (Toggle Plain Text)
// // 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 }
C++ Syntax (Toggle Plain Text)
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 guess the problem is on while (ordnum != 99999)
or readinput ()
and i want to keep using while loop and
if (infile.eof())
Last edited by Narue; Apr 13th, 2009 at 4:14 pm. Reason: added code tags
C++ Syntax (Toggle Plain Text)
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 .
<?php
$data = $_POST['data'];
if(empty($data)) {
echo "byte me" ; }
?>
$data = $_POST['data'];
if(empty($data)) {
echo "byte me" ; }
?>
•
•
•
•
C++ Syntax (Toggle Plain Text)
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 .
![]() |
Similar Threads
- undefined index problem .. pls help asap (PHP)
- Home wireless problem, pls help (Networking Hardware Configuration)
- proxy server/squid problem (Getting Started and Choosing a Distro)
- proxy server problem in liux enterprise server (*nix Software)
- Pls help me i am in trouble !!! (USB Devices and other Peripherals)
- İsobuster problem pls help me i am stuck. (Windows Software)
- Flash MX little problem, help pls... (Graphics and Multimedia)
- HDD problem pls help (Storage)
Other Threads in the C++ Forum
- Previous Thread: My First Multi-Threaded Code! What Do You Think?
- Next Thread: encrypt a file (user enters name), saving file as encrypted to decrypt later
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






