C++ oddity in my code, or compiler?
From: Fargo Holiday (carnifex77_at_chumchum.net)
Date: 10/30/03
- Next message: Jumbo: "Re: 2-dimensional arrays and functions"
- Previous message: Gene Wirchenko: "Re: Apologies"
- Next in thread: Greg: "Re: C++ oddity in my code, or compiler?"
- Reply: Greg: "Re: C++ oddity in my code, or compiler?"
- Reply: Blake Kaplan: "Re: C++ oddity in my code, or compiler?"
- Reply: Richard Heathfield: "Re: C++ oddity in my code, or compiler?"
- Reply: Aggro: "Re: C++ oddity in my code, or compiler?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Next message: Jumbo: "Re: 2-dimensional arrays and functions"
- Previous message: Gene Wirchenko: "Re: Apologies"
- Next in thread: Greg: "Re: C++ oddity in my code, or compiler?"
- Reply: Greg: "Re: C++ oddity in my code, or compiler?"
- Reply: Blake Kaplan: "Re: C++ oddity in my code, or compiler?"
- Reply: Richard Heathfield: "Re: C++ oddity in my code, or compiler?"
- Reply: Aggro: "Re: C++ oddity in my code, or compiler?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|