with the above code-it works fine if i enter 1 or 2 and if i enter 3 it wants for another input but if i enter e then it quits responding
with the above code-it works fine if i enter 1 or 2 and if i enter 3 it wants for another input but if i enter e then it quits responding
To prevent that you need to add to your program. Take the entered data and validate it. ie check if it is a number etc. Use isdigit() or something similar.
Last edited by Fountain; 01-20-2003 at 03:18 PM.
Such is life.
Yeah, well thats because it stores in int's and it cantOriginally posted by Noobie
but if i enter e then it quits responding
store letters in int's, try replacing int with char at every variable
isdigit() -- all i know is it appears to be a function but what to do with it?
it says that isdigit returns 0 if the thing is an integer but how do i tell what it returns and how do i tell it what to evaluate
Im not really formiliar with isdigit(), but i suspect the 1 argument
you pass in, is the argument you want to test to see if it's an
char or an int, if an zero if its not an int and a non-zero if its
an int.
You can't change what it returns, why should you?
Its just that I dont know how to pass an argument into a function and I dont know how to get what code I already have to work, let alone to bring in this function which I have not a clue how to fit into the code I already have
If you're not familiar with functions i redirect you here
int isdigit(int choice)
is that what i use?
Yes, that's what the document i posted earlyer said.
So it gives me a 0 or a 1--what can i do with that?
Then you know if an int has been inputted or a char.
This doesnt work
[copy]
#include <iostream.h>
#include <conio.h>
#include <ctype.h>
int isdigit(int choice);
int isdigit(int choice)
{
return dig;
}
int main()
{
int choice;
int room;
int x=0;
int dig=0;
cout<<"Please choose a room (1 or 2): ";
cin >> choice;
isdigit(choice)
if (dig==0)
cin >> choice;
else
while(x==0)
{
if(choice==1)
x=x++;
else if(choice==2)
x=x++;
else
x=x;
}
if(choice==1)
{
room=1;
cout<<"You enter a room\n";
}
else if(choice==2)
{
room=2;
cout<<"You are in room 2\n";
}
else
{
cout<<"You should not see this.\n";
}
if (room==1)
{
cout<<"Yep";
}
else if (room==2)
{
cout<<"Nope";
}
else
{
cout <<"I need to know how to ask them to plz enter a proper room choice, but how to do that? i don't know.";
}
return 0;
}
[/copy]
isdigit() is already made for you, you can just use it.
it's code by the way not copy