Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?
You are not logged in.
If anybody here can program in C, please help me with this. I have a very small amount of knowledge of the C language, and for some reason, I tried to make a game similar to Colossal Cave. It doesn't work when I build and run it. I mean it will open up and print the first phrase, but it can't recognize input correctly. What did I do wrong?
#include <string.h> #include <stdio.h> int main() { char response; int location; location = 1; printf( "You are on the coast of a circular island in the middle of the ocean.\n" ); scanf("%s",&response); if (response == "look") { printf( "You're on the beach of a somewhat small island. To the south of you there is what appears to be a forest of some sort.\n" ); } else if (response == "go south") { printf( "You've entered a dense forest.\n" ); location = 2; } else if (response == "go east") { printf( "You are on the coast of a circular island in the middle of the ocean.\n" );; } else if (response == "go west") { printf( "You are on the coast of a circular island in the middle of the ocean.\n" ); } else if (response == "go north") { printf( "Why would you go north? You'd drown.\n" ); } else { printf( "I don't understand that.\n" ); } return 0; }
If you don't know much about C, try Visual Basic! You can do professional things with little knowledge in it.
If you don't know much about C, try Visual Basic! You can do professional things with little knowledge in it.
How to use it?I got it but it's hard.Anyway,you can start with Delphi to learn C# and C++ easier.And I suggest you C++,it's advanced of the language you're currently using.
If you don't know much about C, try Visual Basic! You can do professional things with little knowledge in it.
Perhaps doing it in C had a purpose? What if he's trying to learn C? If you can't help him, please refrain from posting in this topic, since help is what he asked for. Especially avoid suggesting that he change his language.
I'm kinda going against my own rule here, as I can't seem to help you. Based on my minimal previous coding experience, I've gotta say it looks sound to me. Let me look it over a bit more.
EDIT:
location=1
Is that the character's location on the map or its "zone", as you may call it? The problem may be that if it's the first option, you fail to change its location after any response. I dunno.
Last edited by JadElClemens (Nov 13 2011 1:37:44 pm)
I hate tall signatures.
Offline
Thanks for trying you guys; I also had this posted on Y! Answers. I got an answer there.
The problem was that I didn't use a buffer, and didn't use STRCMP. I put those in the right places, and it worked great.
And Jojatekok: I'm actually quite good at VB already. But it's VB6, not VB.NET. I tried that, and it really annoyed me.
The "location = 1" says that the character is in zone 1, yeah. And now that I think about it, I really should've used cases instead of elseif statements.
Anyways, thanks!
Last edited by demango (Nov 13 2011 2:48:00 pm)
[ Started around 1738587767.2467 - Generated in 0.177 seconds, 14 queries executed - Memory usage: 1.43 MiB (Peak: 1.55 MiB) ]