I'm using Dev-C++, when I compile I get these errors:
[Warning] In function:
ISO C++
ISO C++
It says the wrong code are
What's wrong? ><Code:if(choice == 'R' || choice == 'r')
I'm using Dev-C++, when I compile I get these errors:
[Warning] In function:
ISO C++
ISO C++
It says the wrong code are
What's wrong? ><Code:if(choice == 'R' || choice == 'r')
Nothing that I can see in that line of code, but sometimes the line number it gives you in the error message is only the line number on which it noticed there was a problem. It's not necesarily where you made the mistake. Perhaps post some more of your code?
Oks.......I've begun to make a text game, here's the code
[Warning] In function:Code:#include <iostream.h> #include <windows.h> #include <string.h> void menu () { cout << "\n\n--Menu--"; cout << "\n[A]ttack" << endl; cout << "[S]pell" << endl; cout << "[T]alk" << endl; cout << "[R]eturn to village" << endl; cin.getline(choice, 5); if(choice == 'r' || choice == 'R') { if(pos==1) { cout << "You are already in town idiot."; } } } int main () { /* Variables */ char pname[80]; int pos = 1; char choice[5]; char gname[] = "Unknown Adventures!!"; /* better name later :-)*/ char pclass[50]; int exp; int gold; /* Begin */ cout << "Whats your name, hero?" << endl; cin.getline(pname, 80); cout << "Hello " << pname << ", and welcome to " << gname; Sleep(1500); cout << "\nWhat do you want to be?" << endl; cout << "Elf, Warrior, Valkyrie, Mage\n"; cin.getline(pclass, 50); cout << "\n\nHello stranger."; cout << "\nOur forest is filled with evil monsters"; cout << "\nKill them and I will bring you a reward."; menu (); Sleep(20000); }
ISO C++
ISO C++
Thanks
Last edited by Noxir; 08-17-2004 at 08:19 AM.
The variable choice has not been defined in menu(), and looks more like a string than a character.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
You've defined choice as an array of chars, and you're testing it as a single char. If you want to test the first char from choice you'd need to call it choice[0]. If you wanted to work with string, then you'd need to implement the special functions.
Also (and this is a comparitively minor problem) I'm not sure if choice is global - but I can never remember all the rules about that. If I want something global I make it as global as I can get it.
Edited:
cin.getline (choice, 0);
void menu (char choice[0])
char choice[0];
Done as you guys said, here's the..
Errors:
ISO C++
ISO C++
`pos'
(Each
[Warning] In function:
too few
at this
More errors? >_< I maybe wrote wrong, could anyone explain??