I am just using it??
Printable View
I am just using it??
you can just use it like
it will return a 0.Code:
isdigit(1);
but............. the user is entering some number which i have defined as choice and i want choice to be evaluated not 1
Then you change the 1 to the variable you want tested:)
You sure you read the tutorial i posted?
Jesus, I don't mean to sound mean... but it's not our job to teach you the language. Read a tutorial or something. http://www.cprogramming.com/tutorial.html
You have MANY errors in your code. Remove the declaration for isdigit at the top of your program.
Change x = x++; to x++;
remove x = x;
Change that toCode:cin >> choice;
isdigit(choice)
if (dig==0)
And finally, remove the depricated headers <iostream.h> and <ctype.h>Code:
cin >> choice;
if (isdigit(choice))
Use <iostream> and <cctype> instead.
So, the top of your program should look like this:
I'm sure there are others, but I quickly looked at your code and those are the ones which stood out.Code:#include <iostream>
#include <conio.h>
#include <cctype>
using namespace std;
my code includes isdigit(choice) but the page u referred me to is multiplying two numbers together not asking for a number, evaluating whether the input is really a number, and then and then doing something based on what number was entered, or otherwise re-asking for a number...so like I really dont know what to do
Now the below code will compile, however the screen wont remain up and if i input e it will not do what i want it to do, which is ask me to input until i input 1 or 2
Code:#include <iostream.h>
#include <conio.h>
#include <ctype.h>
int main()
{
int choice=0;
int room;
int x=0;
int dig=isdigit(choice);
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;
}
No, it won't remain up indeed, put it in a loop.
And the below code here if i enter 3 or e it stops responding instead of asking me to input again
#include <iostream.h>
#include <conio.h>
#include <ctype.h>
int main()
{
int choice=0;
int room;
int x=0;
cout<<"Please choose a room (1 or 2): ";
cin >> choice;
if (isdigit(choice))
cin >> choice;
else
while(x==0)
{
if(choice==1)
x++;
else if(choice==2)
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;
}
change this
into thisCode:if (isdigit(choice))
Code:if (isdigit(choice)!=0)
And in the below code-which I believe does contain a loop-isnt that what while is? - it wont compile because it said i never use x but i DO use x
Code:#include <iostream.h>
#include <conio.h>
#include <ctype.h>
int main()
{
int choice=0;
int room;
int x=0;
cout<<"Please choose a room (1 or 2): ";
while(x==0)
cin >> choice;
if (isdigit(choice))
cin >> choice;
else
{
if(choice==1)
x++;
else if(choice==2)
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;
}
And with this code it works fine if i enter 1 or 2 but once again with e or 3 it stops responding
Code:#include <iostream.h>
#include <conio.h>
#include <ctype.h>
int main()
{
int choice=0;
int room;
int x=0;
cout<<"Please choose a room (1 or 2): ";
cin >> choice;
if (isdigit(choice)!=0)
cin >> choice;
else
while(x==0)
{
if(choice==1)
x++;
else if(choice==2)
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;
}
You seriously need to take some tutorials, that code is a mess,
and half of it wont work. Plz learn the tutorials provided on this
website.
I know...i was hoping you would say why it is a mess-the tutorials dont exactly show how to do this...