So im planning on making a fortune teller program. I got a basic idea of it but when i compile it i get an error. "ISO C++ forbids comparison between pointer and integer."
The way you declare choice1 indicates that you are looking for a single character. However, you are then attempting to put multiple characters into a single char variable which isn't possible. Instead of declaring
char choice1;
include this : #include <cstring>
and declare char* choice1;
this way you will be able to store their answer correctly, not sure if that will fix your error, but it will fix a syntactical error that i picked up, post back if you get the same error XD
Ok, now i don't get any errors but now I can't get the program to execute the else statement. It has something to do with the while statement because if i take it away, it works (with no loop though).
char* is a pointer to a character. It gets special treatment in C so we can use it as a string. However, this: choice1 == "Yes"
checks if the memory address of choice1 equals the memory address of the string literal "Yes".
You don't need to #include <cstring> to use character strings, only to get at functions for working with C strings. There is one such function for comparing strings, but I shan't tell you what it is because there is a better way.
You are using C strings. If you #include <string>, you can use C++ strings. You declare them like this: std::string choice1;
(you can, of course, omit the std:: as you've got usingnamespace std;).
You can compare strings and string literals like this: choice1 == "Yes"
and it should work correctly.
Well, i no longer need help on the if statement. The problem there was the parentheses. Apparently i put them in the wrong places. The problem i have now is the while loop. When it asks you, "Do you like chicken nuggets:" and you answer "asddl" (for example), the while statement does not initiate and the program ends. When i take the while statement out, it works, just that there is no loop.
Believe me, if 'choice1' is still a char* then comparting them like that won't work. In fact, that may well be why the while loop isn't working. Unless you have a good reason not to, use C++ strings as I suggested :)
EDIT: Both Visual C++ and MinGW generate a warning message if you try to compare C strings in this way.
If your Code::Blocks version is up to date then it could only be the warning level of your compiler, which you can change under Settings -> Compiler and Debugger.
Do you know how to use a debugger? You could step through the code, looking at the values of variables at each stage and see where your program logic breaks down.