Hello Fellow Forum Members,
I am using Dev-C++. I have written this code, but during compilation it says cout is not declared in this scope, and also cin not declared. Please can anybody look into the code and rewrite the right one with mu mistake? Thanks!!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
bool accept2()
{
cout << "Do You want to proceed (y or n)?\n";
// write question
char answer = 0;
cin >> answer;
switch (answer){
case'y':
returntrue;
case'n':
returnfalse;
default:cout<<"I'll take that for a no>/n";
returnfalse;
}
Your bit of code worked for me. As FurryGuy said "Did you #include <iostream> ?"?
I also suggest for your switch:
1 2 3 4 5 6 7 8
case'y':
case'Y':
returntrue;
case'n':
case'N':
returnfalse;
default:cout << "\nI'll take that for a no>\n";
returnfalse;
Do not forget about capital letters. And in line 12 of your code for default the text that is output ends with /n and should be \n. The \n at the beginning of the line I added for testing.
One cannot use undeclared identifiers in C++, because the compiler does not know what they are. That is why one has to declare (function, variable, type identifiers) first, before use.
It would be a pain to write every declaration yourself. That is why the library writers have written some for us and stored into files that the preprocessor presents for the compiler in our behalf -- but only if you do use the #include directive.