View Single Post
  #3 (permalink)  
Old August 23rd, 2004, 09:44 AM
davekw7x davekw7x is offline
Authorized User
 
Join Date: Feb 2004
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What version dev-c++ are you using?

Mine (version 4.9.8.0) didn't compile correctly. The main() must be type int according to the c++ standard.

So change
Code:
float main()
to

Code:
int main()
cout and cin are part of the std namespace. Older versions of C++ didn't have namespaces, and using the headers that you have included gets around the namespace problem, but it is highly recommended, for now, that you use the following in stead of your #include statemsnts:
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
That should make your program ok to compile with any C++ compiler that complies with the C++ standard.

Now as for your logic:

You could use

Code:
if ((x != 1) && (x != 2) && (x != 3))
Think about the logic, and put it into words.

You want to continue if

(x is equal to 1) or (x is equal to 2) or (x is equal to 3)

That means you want to quit if

(x is not equal to 1) and (x is not equal to 2) and (x is not equal to 3)

You will be making this kind of decision many times in your life (including in programs).

Formally, the equivalence between the two above statements is known as DeMorgans Rule (from DeMorgans Theorem).

Good Luck

Dave
Reply With Quote