en972 Member Posts: 562 From: NOT TELLING! Registered: 08-27-2004 |
I'm makeing a puzzle game in c++ . This is a basic form of it I'll post the code before i explain whats wrong #include <iostream>
(2) [error] syntax error before 'else' ------------------ |
|
Klumsy Administrator Posts: 1061 From: Port Angeles, WA, USA Registered: 10-25-2001 |
you don't have a scope. if (password == kerry) so the IF statement is just doing that first line.. (then there is no else after that, so it assumes its finished, and shows the other lines below normally cout<< "Type the name of a folder below to access it." <<endl; else
------------------ |
|
CoolJ Member Posts: 354 From: ny Registered: 07-11-2004 |
also your string should be set to something string kerry("mypass1"); |
|
en972 Member Posts: 562 From: NOT TELLING! Registered: 08-27-2004 |
wow, thanks guys, I am still getting used to surrounding everything in braces string kerry ("mypass1"), ooooh. Ok, I get it. ------------------ |
|
en972 Member Posts: 562 From: NOT TELLING! Registered: 08-27-2004 |
I still always get access denied ------------------ |
|
graynod Member Posts: 17 From: richmond, VA, USA Registered: 09-28-2004 |
This might sound nutty, but what are you entering? It looks like your're expecting a match for "kerry", is that the input you're entering? Just a thought.... May God bless you as you study and learn. ------------------ |
|
CobraA1 Member Posts: 926 From: MN Registered: 02-19-2001 |
kerry is the variable the string is stored in. "mypass1" is the string. If you want "kerry" to be the password, try
------------------ Switch Mayhem now available! Get it here [This message has been edited by CobraA1 (edited March 04, 2005).] |
|
graynod Member Posts: 17 From: richmond, VA, USA Registered: 09-28-2004 |
Yah, I didn't write what I meant clearly at all, shouldn't have used the double quotes I guess. What I wonder is, if say the password the user enters is the string "password", and the value stored in kerry is "mypass1", then the test will fail; is this what's happening when en972 tests it? Just a thought! May God bless you all. ------------------ |
|
CapnStank Member Posts: 214 From: Sask, Canada Registered: 12-16-2004 |
First off don't you need to load string.h? or #include <string> using namespace std; 2nd off I set strings/characters like: works the same for me. ------------------ |
|
FredSmith Junior Member Posts: 2 From: Registered: 03-06-2005 |
I'd also strongly recommend replacing using namespace std with using std::cout; etc. string s("test") is better because it calls the constructor, string s = "456453" calls the empty constructor then the = operator. system("PAUSE") is not C++, it's system specific. I'd avoid such calls if I could. You're obviously in at the deep end here, you should buy a beginners book like 'teach yourself C++ in 24 hours' and work through it before thinking about writing any games. The world is full of really bad games from people who didn't learn to program first. I admire your enthusiasm, but you'd do better to get some basic syntax under your belt before attempting anything remotely complex. :-) |
|
en972 Member Posts: 562 From: NOT TELLING! Registered: 08-27-2004 |
Oh hey, um, wow I almost forgot about this. Thanks for the help I'll pick it back up again. I've really been using GUI's. Oh and Thanks for suggestions on books.. But I have this friend at church, very exellant programmer, hes teaching me now. Thanks alot for all your help, espically you fredsmith ------------------ |