c++ problem need help pls

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2009
Posts: 2
Reputation: wuzj1988 is an unknown quantity at this point 
Solved Threads: 0
wuzj1988 wuzj1988 is offline Offline
Newbie Poster

c++ problem need help pls

 
0
  #1
Apr 13th, 2009
this is my program
  1. //
  2. // custorderscf2.cpp
  3. //
  4. #include <cstdlib> // student ...... Jones, Patricia
  5. #include <iostream> // section ...... MW row .... 4
  6. #include <fstream> // due date ..... xx/xx/xx
  7. #include <iomanip> // refer to ..... Gaddis Ch3
  8.  
  9. void SetPrecision(int); // procedure prototype
  10. using namespace std; // avoid std::cin >> ...
  11.  
  12. /* declare global data elements */
  13. int ordnum; // input variables
  14. string partnum; //
  15. int quantity; //
  16. double price; //
  17.  
  18. void readinput (void); //
  19. ifstream infile; // declare file object
  20.  
  21. int main (void) // main function header
  22. { // begin block
  23.  
  24. int oldordnum; // old order number
  25. double de1extprice; // detail line ext price
  26. double cf1extprice; // order total
  27. double cf2extprice; // report total
  28.  
  29. /* begin procedural code */
  30. SetPrecision(2); // set floating points
  31. cf2extprice = 0; // clear report total
  32. infile.open("custorders.bdl"); // open input file
  33.  
  34. /* test for successful open */
  35. if(!infile)
  36. {
  37. cout << "Input file open error!";
  38. exit(-1); // error pgm stop
  39. }
  40.  
  41. /* print column headers */
  42. cout << setw(10) << "ORD NUM"
  43. << setw(10) << "PARTNUM"
  44. << setw(10) << "QUANTITY"
  45. << setw(10) << "PRICE"
  46. << setw(12) << "EXT PRICE" << "\n\n";
  47.  
  48. /* begin processing loop */
  49. readinput(); // read first record
  50. oldordnum = ordnum; // save the control field
  51. while(ordnum != 99999); // test for more data
  52. {
  53.  
  54. cf1extprice = 0; // clear order total
  55. while(ordnum == oldordnum) // same group ?
  56. {
  57.  
  58. cout << setw(10) << ordnum // detail calc
  59. << setw(10) << partnum // level one calc
  60. << setw(10) << quantity // print detail
  61. << setw(10) << price;
  62. de1extprice = quantity * price; //
  63. cout << setw(12) << de1extprice << endl;
  64. //
  65. cf1extprice = cf1extprice + de1extprice; //
  66. //
  67. readinput(); // read next record
  68. }
  69. cout << endl;
  70. cout << setw(52) << cf1extprice << "\n\n"; // order total
  71. cf2extprice = cf2extprice + cf1extprice; // level two calc
  72. oldordnum = ordnum; // save the control field
  73. } //
  74. cout << endl;
  75. cout << setw(52) << cf2extprice; // print report total
  76.  
  77. /* close file and stop run */
  78. cout << endl;
  79. infile.close(); // close file
  80. return(0); // int return to o/s
  81. } // end main block
  82.  
  83. void readinput (void)
  84. {
  85. infile >> ordnum >> partnum >> quantity >> price;
  86. if (infile.eof())
  87. ordnum = 99999;
  88. return;
  89. }
  90.  
  91. void SetPrecision(int pDecPlaces) // procedure header
  92. {
  93. cout.setf(ios::right); // right-justified
  94. cout.setf(ios::fixed);
  95. cout.setf(ios::showpoint);
  96. cout.precision(pDecPlaces);
  97. return; // return to caller
  98. }
and the text is
  1. 21608 AT94 11 21.95
  2. 21608 KL62 2 329.95
  3. 21610 DR93 1 495.00
  4. 21610 DW11 1 399.99
  5. 21613 KL62 4 329.95
  6. 21613 AT94 2 21.95
  7. 21613 FD29 1 159.95
  8. 21614 AT94 10 21.95
  9. 21614 KT03 2 595.00
  10. 21617 BV06 2 794.95
  11. 21617 CD51 4 150.00
  12. 21619 DR93 3 495.00
  13. 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())
Last edited by Narue; Apr 13th, 2009 at 4:14 pm. Reason: added code tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 90
Reputation: unbeatable0 is an unknown quantity at this point 
Solved Threads: 12
unbeatable0 unbeatable0 is offline Offline
Junior Poster in Training

Re: c++ problem need help pls

 
0
  #2
Apr 13th, 2009
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
Last edited by unbeatable0; Apr 13th, 2009 at 4:53 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 211
Reputation: rahul8590 is on a distinguished road 
Solved Threads: 11
rahul8590's Avatar
rahul8590 rahul8590 is offline Offline
Posting Whiz in Training

Re: c++ problem need help pls

 
0
  #3
Apr 14th, 2009
  1. 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" ; }
?>
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,857
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 120
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

Re: c++ problem need help pls

 
0
  #4
Apr 14th, 2009
Originally Posted by rahul8590 View Post
  1. 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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,951
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 306
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: c++ problem need help pls

 
0
  #5
Apr 14th, 2009
Originally Posted by ithelp View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 2
Reputation: wuzj1988 is an unknown quantity at this point 
Solved Threads: 0
wuzj1988 wuzj1988 is offline Offline
Newbie Poster

Re: c++ problem need help pls

 
0
  #6
Apr 15th, 2009
am i stupid?
thanks for everyone's replying
especislly unbeatable0
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC