Menu

Newbie Code not working =[

2007-07-06
2012-09-26
  • Nobody/Anonymous

    include <cstdlib>

    include <iostream>

    using namespace std;

    int main()
    {
    int hello = 2;
    do {
    system("PAUSE"); //Only code in do-while loop
    while (hello!=1);
    }
    }

    How comes it dont work, thanks!

     
    • Nobody/Anonymous

      "How comes it dont work"
      Don't you mean will not compile?
      This will compile & run, but you need to add a way to exit the program.

      int main() {
      int hello = 2;
      do {
      system("PAUSE");
      } while (!hello);
      }

      M.B.

       
    • Anonymous

      Anonymous - 2007-07-07

      You simply placed the closing brace on the wrong side of the while statement; so the while is inside the do-while, not part of it!

      Consider using while in preference to do-while, it is less error prone and in this case makes no difference to the functionality. Either way, check teh syntax of do-while you had:

      do{... while(condition);}

      instead of

      do{...}while(condition);

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.