C++ oddity in my code, or compiler?

From: Fargo Holiday (carnifex77_at_chumchum.net)
Date: 10/30/03


Date: Thu, 30 Oct 2003 17:49:22 GMT

Hello again,
I'm working on a command line game, just a simple exercise to expand my
programming horizons, and I've run into something unusual.

This snippet here ran just fine just yesterday:

#include <iostream>
#include <stdlib.h>
#include "tanks.hpp"

using namespace std;

int main(int argc, char *argv[])
{
  int temp;
  tanks Player1;
  tanks Player2;
  string player1;
  string player2;
  int player=0;
  int exit=0;

  cout << "Who is player 1? ";
  cin >> player1;
  cout << "Who is player 2? ";
  cin >> player2;
  cout << "Ok, and, indicating by a 1 or 2, which player is setting up now?
";
  cin >> player;
  if (player!=1||player!=2)
  {
    cout << "There are two players here, and ONLY two!" << endl;
    exit=1;
  }

Now, when I compile and run, the if statement is always evaluating true. The
only change was in my tanks class, which
I cannot fathom being an issue. Just to be sure, however, I have tried a
similar conditional in a seperate project file and
the results were identical. If I change to a less than, greater than setup
it works fine.
For instance:

 if (player<1||player>2)
  {
    cout << "There are two players here, and ONLY two!" << endl;
    exit=1;
  }

This evaluates normally. So, my question is if there is any c++ standard
reason that my usage of != isn't working properly,
or should look further into a possible compiler issue?

Thanks.



Relevant Pages

  • Stumped by a Syntax Error
    ... On the second snippet, when the set method is entered, it fails to ... cannot think of a reason why one would compile and the other not. ... Dim reqLineList As CList ... Public Property Set Approval ...
    (microsoft.public.vb.general.discussion)
  • Compiling snippets of python code
    ... I need some advice on compiling snippets of python source at runtime. ... I am rewriting an old Java app in python. ... Having seen the docs on python's compile module, ... When the snippet is executed I would ...
    (comp.lang.python)
  • Re: Question about algorithm-to-architecture mapping
    ... Compile the code - grab the code snippet of interest - simulate it in ... Time was you might not even recognize the snippet after the compiler ... As soon as your algorithm starts to rely on internal ...
    (comp.dsp)
  • Re: newbie: actionPerformed counting performances? :(
    ... "Libribex" wrote in message ... I might have looked at your code, but it was a snippet! ... I tried to compile it and got errors, ... http://www.AThompson.info/andrew/ personal site ...
    (comp.lang.java.help)