0

I was working on a school project to make a blackjack/21 console application. The program is somewhat long and complicated, so will only put the offending code here. Complete code will be below.

cout << "Before comp instruct";
cout << endl << "Computer: ";
cout << "After comp instruct";

It will always print the first statement, but it sometimes stops immediately after that. It happens only sometimes, depending on the input in the program. I (and my teacher and peers) could not figure out why this program stops after the first statement. At least one other person in the class is having a similar problem.

These were done using CodeWarrior IDE on a Windows 7 Dell desktop.

alexwho314
  • 29
  • 2
  • 9
  • Complete code in a comment is an extremely bad idea. An [SSCCE](http://sscce.org/) in the question would be better. – chris Jun 02 '13 at 20:46
  • 3
    add `cout.flush();` or another `endl`. – Elazar Jun 02 '13 at 20:50
  • We didn't ask for your entire program, only the code relevant to your problem. – David G Jun 02 '13 at 20:52
  • I'm sorry everyone, I'm new here. I'll try to get an SSCCE version up tomorrow. Elazar, I'll try that when I get to my compiler tomorrow. – alexwho314 Jun 02 '13 at 20:53
  • As Elazar points out, unless you flush the stream using `cout << endl << "Computer: " << flush;` (or another endl that calls flush internally), you're not guaranteed to see the output until the buffers are full and automatically flushed. Which may never happen if you're waiting for input. – Joachim Isaksson Jun 02 '13 at 20:56
  • @alexwho314, There are online compilers. – chris Jun 02 '13 at 20:58
  • *"It happens only sometimes, depending on the input in the program"* - Therein, I suspect, lies your answer. – Component 10 Jun 02 '13 at 20:58
  • What compiler are you using that uses `iostream.h` and `vector.h`? About 10 years ago `` and `` became the standard headers. – Jesse Good Jun 02 '13 at 21:00
  • @JoachimIsaksson, I will try using flush tomorrow. – alexwho314 Jun 02 '13 at 22:33
  • @chris, I tried other compilers, but they don't work with my code. They keep saying there are errors. – alexwho314 Jun 02 '13 at 22:34
  • @Component10, I don't see how input can affect it because there is no decision being made between the first and second statement. – alexwho314 Jun 02 '13 at 22:35
  • @JesseGood, I'm using CodeWarrior. I think it's around 10 years old. The school hasn't purchased new programming software recently. We still use VB6 (from 1999) in class. – alexwho314 Jun 02 '13 at 22:37
  • @alexwho314, I suggest getting rid of those errors. They're there to help you. – chris Jun 02 '13 at 22:48
  • @chris, they are really strange errors like saying it doesn't recognize certain keywords, like return, do, or if. – alexwho314 Jun 02 '13 at 22:58
  • @alexwho314, It's probably another error causing that. Start from the top. – chris Jun 02 '13 at 23:03
  • @chris, the specific library I'm required to use (apstring.h) isn't compatible with newer compilers. – alexwho314 Jun 03 '13 at 00:06
  • @alexwho314, Is that the same one used on the AP exam? That's really too bad in any case, though :/ Using really old tools doesn't really benefit anyone nearly as much and there are tons of free new solutions. – chris Jun 03 '13 at 00:31
  • @chris, the curriculum uses the software the AP exam used to use. The AP exam has since moved on. – alexwho314 Jun 03 '13 at 00:36
  • @alexwho314, Yeah, I wished it was still in C++ when I wrote it this year, but I noticed they killed off the string class and had GridWorld. At least the documentation for it is at the back. – chris Jun 03 '13 at 00:39
  • @JoachimIsaksson, I tried using flush. It finally printed the second statement, but it would not help print the third. – alexwho314 Jun 03 '13 at 16:30
  • @alexwho314 `flush` will send all text written so far to the console. If you want the third line written, just flush at the end of that instead. – Joachim Isaksson Jun 03 '13 at 16:56
  • @JoachimIsaksson, I had tried it, but it didn't help. I'm working on creating a minimal version of the problem. – alexwho314 Jun 03 '13 at 16:58
  • @chris, I created an SSCCE version and managed to solve my program. I had an infinite loop in another portion of the program. I still am clueless about why that would prevent these statements from printing properly. – alexwho314 Jun 04 '13 at 12:58

0 Answers0