![]() |
What's wrong with this code?
This is a code for a game that I'm making... it's not the whole game obviously, just the menu so far... but I can't figure out what the 5 errors are...
:
#include <iostream> |
Check your if statements! You need to add braces { } around the body after the if statements. Another problem is that you never included the string header file. You must do that in order to use the string class.
Also, you redeclare all of your variables after the loop iterates completely. This might not be a good idea. *TIP*: Add the error messages when you post something like this! EDIT: Are you and Arnack working together on this? Maybe the same person? |
Yes, me and him are working together. Once we learn C++ well enough we're going to try to start a game company.
|
Good luck with that! I hope for the best.
|
Thanks ^_^
|
So, will this fix it?
:
#include <iostream> |
Recompile that and see for yourself.
|
Ok, now when I enter Yes for if I'm ready, or if I had entered No I'm guessing the same would happen, it indefinitely prints the contents of the first IF statement (at least I think that's what it was, it was moving fast).
No errors in compilation obviously... Edit: Upon closer inspection, it was indefinitely printing the text from the question where it asks if you are ready. Edit: I can input 1 for yes or 2 for no, but I want to be able to input yes or no. Also, when it asks me what I want to do, I choose 1 or 2 and it restarts the whole thing. Edit: Ok I defined Yes as 1 and No as 2 and changed the 1 and 2 in the if statements to Yes and No, but now when I enter my choice it keeps printing the questions over and over. |
:
int ready;Does Yes and 1 look the same? Well, no. "Yes" is a string, while 1 can be the value of an int. cin is expecting an int, so why are you giving it a string? |
Would I add this?
int 1 = Yes; int 2 = No; or int Yes = 1; int No = 2; Because I tried that second one and the error in my third edit of the above post happened... Edit: Happens either way... |
| All times are GMT -5. The time now is 3:10 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC