Whiteflags has given you some excellent advice, although it may be just a tad complex for someone working on one of their very first programs...
Code:
int main(void) /* does void simply mean close the program once done running int main? */
{
int yes;
int no;
int ansr;
printf("You are at the entrance of a castle.\nDo you wish to enter?\nYes or No:\n");
scanf("yes", &yes "no", &no); /* syntax error before string constant? */
ansr("yes", &yes + "no", &no);
if ansr = yes then printf("You have entered into the castle.");
getch();
}
The void in int main (void) indicates that you are not going to process command line arguments in your program. When you see that in a procedure definition it means no variables are passed into the function.
First of all you can't just make stuff up... C is a serious idiot. You have to speak it's language EXACTLY or it's going to get all confused on you. It has a very short list of "keywords" it understands (if else while for etc.) the rest is going to cause it problems. Lines like...
Code:
scanf("yes", &yes "no", &no);
ansr("yes", &yes + "no", &no);
... no matter what you want it to do are just going to cause a "syntax error", the compiler's way of saying "I don't understand".
So... lesson 1, learn to speak C... 'cause it ain't never gonna learn your language.
Now, lets take a look at the intent of your program... What do you want to do?
You say you're looking for a simple decision from your operator... Yes or No... in response to a simple question printed on screen.
Ok... that's pretty easy. In general you can assume that Y or y mean Yes and *everything else* means No. The reason I generally suggest that is that some operators are very dumb, very few actually read the screen, so if they're hammering around on the keyboard, you want your program to abort rather than causing system errors.
So we can safely say that unless the operator types a Y or a y (and they are two different things in C) you want your program to exit.
The first thing to figure out is how to print the message... The C library has a nifty function puts() that prints strings on the screen... Very handy. (Look it up!)
Code:
#include <sdtlib.h>
#include <stdio.h>
int main(void)
{
// print message on screen...
puts("Do you want to enter THE CASTLE : y/n :");
return 0;
}
So... compile what you've got so far and see what it does...
Now... How do we get that Y or y from the keyboard? The C library has a standard function called getchar() which reads a single keystroke then carries on... perfect for what you want. (Look it up!)
Code:
#include <sdtlib.h>
#include <stdio.h>
int main(void)
{
int ans; // for user response
// print message on screen...
puts("Do you want to enter THE CASTLE : y/n :");
// get user response from keyboard
ans = getchar();
return 0;
}
Compile again and see how this works....
Now we need to decide what to do with that answer...
You've said that if they answer Yes (Y or y) you want to print a message. Anything else should cause a program exit. The logical way to think about this is "if they type anything but a Y or a y, the program ends"... Now to code this we use an "if" statement, similar to the one Whiteflags showed you. (You should look this up too!)
To do this we have to test the value from the keyboard stored in the ans variable. We have a very limited group of choices == (equals) != (not equal) etc. In this case it's the != we're interested in. Further we have two possibilities Y and y so we have to test both. The && operator says "and"... so we get the new line below...
Code:
#include <sdtlib.h>
#include <stdio.h>
int main(void)
{
int ans; // for user response
// print message on screen...
puts("Do you want to enter THE CASTLE : y/n :");
// get user response from keyboard
ans = getchar();
// exit unless Y or y entered.
if ((ans != 'Y') && (ans != 'y'))
exit(0);
// the only way to get here is with a Yes answer so print the message
puts("You have just entered The Castle!... Welcome");
return 0;
}
I think this is about the simplest form of this task possible...
This is the general flow of things when developing programs... think in little tiny blobs... always speak the compiler's language... build in bits and pieces. As you gain more experience your blobs will get a bit bigger and things will get easier.