d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Program Works Differently On Friend's Pc
Add Reply New Topic New Poll
Member
Posts: 2,769
Joined: Dec 24 2009
Gold: 14.00
May 18 2013 03:19am
I made a program, where it works fine for me but it infinite loops for a friend. Does this have something to do with header files? If so, how can I resolve that?

Also, I'm using code blocks

This post was edited by Foxic on May 18 2013 03:20am
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
May 18 2013 03:24am
It's not like we have to see the code or anything.
Member
Posts: 3,451
Joined: Feb 26 2010
Gold: 0.20
May 18 2013 11:58am
could be a different system? unix/dos
could be that you're pulling info from an unallocated memory space so it'd be different depending on the computer/time run.

There's a lot of possibilities hard to figure out without the code
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
May 18 2013 05:10pm
yeah might be stuck in a while loop or something because it can't find something it needs

Member
Posts: 2,769
Joined: Dec 24 2009
Gold: 14.00
May 18 2013 09:36pm
The code is pretty long, not sure if this excerpt will be understandable, I'm making a simple tic tac toe game

Code
while (winCheck(xo) == 0){     // while there are no 3 x's or 3 o's in any row
       do {
       freeSpace = 1;          //assume there's a free space wherever you'e trying to put an x or o
       while (row < 1 || row > 3 || intCheck == 0){    //makes sure user inputs an int of values 1-3
       intCheck = 1;            //assume user inputs an int
       cout << "enter row (1-3)" << endl;        <---- this starts looping on friend's pc if he inputs a non-int
       cin >> row;            
       if (cin.fail()){  
           intCheck = 0;
           cin.clear();
           cin.ignore();
       }
       }
       while (column < 1 || column > 3 || intCheck == 0){  //same as above
       cout << "enter column (1-3)" << endl;
       cin >> column;
       if (cin.fail()){
           intCheck = 0;
           cin.clear();
           cin.ignore();
       }
       }
       if (xo[row-1][column-1] == 'x' || xo[row-1][column-1] == 'o'){  //makes sure there's a free space, if not then loop resets and have to put in new inputs
           cout << "Already an X or O there" << endl;         <----- this starts looping on friend's pc if it's not a free space
           cin.clear();
           cin.ignore();
           freeSpace = 0;
           row = 4;
           column = 4;
       }

       } while (freeSpace == 0 || (row < 1 && row > 3) || (column < 1 && column > 3));
       xo[row-1][column-1] = 'x';
       dumbAi(xo);
       print(xo);
       row = 4;
       column = 4;
   }


This post was edited by Foxic on May 18 2013 09:37pm
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
May 18 2013 11:56pm
try compiling with
Code
-Wall

and use a debugger to see what is going wrong

This post was edited by Azrad on May 18 2013 11:56pm
Member
Posts: 9,759
Joined: Jun 10 2007
Gold: 42,069.33
Jun 6 2013 05:52pm
your spacing is horrid.

anyway it loops forever when a non int is entered?

that means your error checking is not right.

the example below will loop forever until a integer is entered. that way you know a integer is always entered going into the while loop.

Code

while(!(cin >> num) || cin.peek() != '\n')                                       //change num to the name of your integer
  {
    cout << "Please enter an INTEGER: ";
    cin.clear();
    cin.ignore(30000, '\n');            
  }
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll