473,320 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Valid answer 1-10 only. All else gets error message.

jel
I ran what was submitted in several forums, but it's not exactly what
i'm looking for. I'm dy'n over here. Ah, the frustrations of an
amateur programmer. I included the code below in c++. which details
what i'm looking for. I'm sure its just a small detail. But I'm in the
dark.

// numbers1to10only.cpp

#include <iostream.h>

int main()
{
double x; // Variable for user input

do // I want it to loop until user <ctl+c> to quit.
{
cout << "\nWhich NUMBER 1-10 do you wish to display?\n";
cin >> x; // Get Input from user.
cout << "\nThe VALUE you entered was: " << x << ".";
if ((x < 1) || (x > 10))

/* I'm on my second bottle of asprin now. Still no effect.

I only want the numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 to be
valid. No #'s containing decimals (before, middle, or after), no
letters of any kind, no special characters of any kind, etc...
**I just want the numbers 1-10 to be valid.** All else, I want
the error "below" to be displayed. ALSO, even after the user gives
what is asked (above), I'm looking to have it prompt again with
the same question above, (As it currently does above.)

I've tried several options from online forums but not exactly
what i'm looking for. Very close thought. If you run throught
my program as it is now, you'll see that #'s 1-10 (1.2, 9.0)
come up as valid answers. That's not what i'm looking for.
Also, if the user enters an (or several) alpha character, or
special character, the program does a scrolling thing with the
error below. I don't know how to make that stop. I just want
the error to display once, then prompt user with ? above. You'll
see what I mean if you run the program and put in various imputs.

Sorry about length of explination.*/

{
cout << "\nERROR, Ahhh!, You're trying to be funny.\n";
cout << "However, the NUMBER: " << x << " you selected is not
valid.\n";
cout << " It must be 1-10.\n";
cout << " Nice try though, but do try again.\n";
cout << "************************";
}
} while ((x > 1) || (x < 10));
return 0;
}

Thanks for any help you-all can provid.
JEL
Jul 22 '05 #1
1 2126
"jel" <lo*******@hotmail.com> wrote in message
news:19**************************@posting.google.c om...
I ran what was submitted in several forums, but it's not exactly what
i'm looking for. I'm dy'n over here. Ah, the frustrations of an
amateur programmer. I included the code below in c++. which details
what i'm looking for. I'm sure its just a small detail. But I'm in the
dark.

// numbers1to10only.cpp

#include <iostream.h>

int main()
{
double x; // Variable for user input

do // I want it to loop until user <ctl+c> to quit.
{
cout << "\nWhich NUMBER 1-10 do you wish to display?\n";
cin >> x; // Get Input from user.
cout << "\nThe VALUE you entered was: " << x << ".";
if ((x < 1) || (x > 10))

/* I'm on my second bottle of asprin now. Still no effect.

I only want the numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 to be
valid. No #'s containing decimals (before, middle, or after), no
letters of any kind, no special characters of any kind, etc...
**I just want the numbers 1-10 to be valid.** All else, I want
the error "below" to be displayed. ALSO, even after the user gives
what is asked (above), I'm looking to have it prompt again with
the same question above, (As it currently does above.)

I've tried several options from online forums but not exactly
what i'm looking for. Very close thought. If you run throught
my program as it is now, you'll see that #'s 1-10 (1.2, 9.0)
come up as valid answers. That's not what i'm looking for.
Also, if the user enters an (or several) alpha character, or
special character, the program does a scrolling thing with the
error below. I don't know how to make that stop. I just want
the error to display once, then prompt user with ? above. You'll
see what I mean if you run the program and put in various imputs.

Sorry about length of explination.*/

{
cout << "\nERROR, Ahhh!, You're trying to be funny.\n";
cout << "However, the NUMBER: " << x << " you selected is not
valid.\n";
cout << " It must be 1-10.\n";
cout << " Nice try though, but do try again.\n";
cout << "************************";
}
} while ((x > 1) || (x < 10));
return 0;
}

Thanks for any help you-all can provid.
JEL


Look here for code that will reject non numbers:

http://www.parashift.com/c++-faq-lit....html#faq-15.2

Though the code there will convert floating point numbers to ints, and
accept them.

This would reject floating point numbers:

#include <iostream>

int main()
{
std::cout << "Enter a number, or -1 to quit: ";
float i = 0;
while (std::cin >> i) { // GOOD FORM
if (i == -1 || i != (int) i) break;
std::cout << "You entered " << i << '\n';
}

}

--
Derek
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: mkremser | last post by:
Hi NG! In a XSD, we (try to) specify that a node ("BsqCallInfo") has two attributes and can have any nodes as its children: <xsd:element name="BsqCallInfo"> <xsd:complexType> <xsd:choice...
12
by: Mr. Clean | last post by:
As you may know, spammer use this technique to get by filters. <!H>It<!W> is<!N> <!K>a<!L> w<!Q>el<!Q>l <!X>k<!O>now<!B>n <!F>f<!G>a<!V>c<!O>t <!S>th<!B>at p<!R>eopl<!J>e<!G> <!Z>who...
9
by: CMAR | last post by:
I have been trying to validate a frameset document with either the HTML 4.01 or XHTML Transitional DOCTYPE. But I am finding that various <frameset> attributes ( framespacing="0", border="0",...
4
by: c.verma | last post by:
I am stuck on one silly thing.It is just about calling unmanaged code in the C# win/web application. This is what I did: 1) Created a VB dll xyz.dll. 2) Since this is unmanaged dll, I used...
2
by: tlk | last post by:
Hi, everyone. I'm having a problem that I hope some more experienced developers can help me figure-out. We have a project called Records that has been around for a year or so. We're currently...
21
by: Kannan | last post by:
Its been a while I have done pure C programming (I was coding in C++). Is the following function valid according to standard C? int main(int argc, char *argv) { int x; x = 9; printf("Value...
3
by: cmay | last post by:
The question is: Which one of the following is NOT a valid state management tool? And the possible answers are: 1. Hidden Form Fields 2. Cookies
2
by: chiasien | last post by:
Hi All, I am new learner for Java. My doubt is: public static void mystery (int list , int size) parameter: int list , int size
9
by: Marijn | last post by:
Hey everybody, I was wondering if the following would be a valid JavaScript assignment vor a variable and if anybody knows this to work in IE6 or lower? var someVar = (typeof(someVar) ===...
7
by: Christian Hackl | last post by:
Hi everyone, I've got a question about what makes the "img" element's width/height attributes valid HTML or XHTML. First of all, this is a rather theoretical question, but digging through the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.