Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 10-16-2005, 05:39 PM   #1 (permalink)
bradleyc
Registered User
 
Join Date: Aug 2005
Posts: 17
bradleyc is on a distinguished road
What is wrong with this statement?

If i enter 1, 2, 3, 4 ... still returns "ERROR: Invaild Input"


Code:
      clrscr();
      cout << "     " << endl;
      cout << " Which event would you like to select? "<<endl;
      cout << "" << endl;
      cout << " 1. 100m Free" <<endl;
      cout << "" << endl;
      cout << " 2. 200m Back" <<endl;
      cout << "" << endl;
      cout << " 3. 400m Medley" <<endl;
      cout << "" << endl;
      cout << " 4. 800m Back" <<endl;
      cout << "" << endl;
      cout << " Your Selection: ";
      cin >> currentE;
      	if (currentE < '1' ||  currentE > '4')
         {
         	clrscr();
         	cout << " " << endl;
         	cout << " ERROR: Invaild Input" <<endl;
         	cout << " Press any key to exit ....";
         }
            	input = getch();
               if (input)
					{
        			swim::displayMenu();
					}
bradleyc is offline   Reply With Quote
Old 10-16-2005, 09:48 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
This isn't nearly enough... What is currentE declared as ? int, char, string, long, double, float, what ?? The comparison is against a char, if it was declared int, then the comparison should be against ints, the int value for the char '1' is 49 and for '4' it's 52.
If the input is treated as an int, then comparing it to the char will say
Code:
if( (value between 1 and 4) < 49 || (value between 1 and 4) > 52)
This, as you can see is giving false on every run, no matter if you type 1, 2, or 8
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Whats wrong with this? TheShadow MS Technologies ( ASP, VB, C#, .NET ) 2 05-23-2005 09:10 PM
Something wrong with the view script redhead Lounge 1 10-11-2004 01:58 PM
Using ORDER BY in a select statement Epsilon PHP 3 08-22-2004 02:28 PM
'OR' statement spinhead PHP 5 03-29-2004 06:18 AM
How to add an error statement w00t Standard C, C++ 4 08-13-2002 10:54 PM


All times are GMT -8. The time now is 08:37 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting