Why is it that when I input b I still get "not valid"?
#include %26lt;stdio.h%26gt;
int main(void)
{
int type;
int valid;
char c,b;
printf("Enter you vehicle type: ");
scanf("%d", %26amp;type);
valid = c,b;
if(type != valid)
printf("not valid\n");
return(0);
}
Any help would be greatly appreciated.
Problem with my C code. Need help urgently!?
I am trying to rewrite your program by understanding in the following way.
Let c meant for car and b for bike.
#include %26lt;stdio.h%26gt;
int main(void)
{
int type;
int valid;
printf("Enter you vehicle type: ");
scanf("%d", %26amp;type);
valid = 'b';
if (type != valid)
printf("not valid\n");
else
printf("valid\n");
return(0);
}
In this code, If you enter b it will - valid. Enter c will be - not valid
Reply:The line
valid = c,b;
Doesn't do what you think it does.
If I understand your intentions correctly, your best shot would be scraping the "valid" variable altogether (and the problematic line) and change
if(type != valid)
into
if( (type!="c") %26amp;%26amp; (type!="b") )
PM me if you would like more help.
Reply:Man, I wish I could help you. I did a little work in C, and then moved on to C++. Either way, I'm not fluent enough right now to answer your question.
Honestly, I'd try a dedicated C# programming forum. Yahoo Answers can provide some great input, but most of the hardcore programmers are probably busy on their forums instead.
Reply:what is c? it's unknown, unset.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment