-
Option undeclared?
When I compile my script using Dev-C++, they say that on line 38 ( if(strcmp(option, "1") == 0) ), 'option' is undeclared, but i am sure it is already declared.
Code:
Code:
#include <iostream>
#include <string>
int main(void)
{
char insane[100];
std::string strinsane = "";
cout<<"\t### m4 installer v0.1 ###";
cout<<"\n";
cout<<"\t### (c) Microsoft 2002 ###";
cout<<"\n";
cout<<"\t### Testers: DO NOT GIVE THIS TO YOUR FRIENDS OR ANYBODY ELSE ###";
cout<<"\n";
cout<<"\t### Press enter to begin. ###";
cin.getline(insane, sizeof insane, '\n');
if(strcmp(insane, "insanityclownZ") == 0)
{
cout<<"WTF ! How did you know?\n";
cout<<"If you read the source code you die! insanityclownz";
}
else
{
cout<<"\t## 1. Download Longhorn M4 from MS ##\n";
cout<<"\t## 2. Exit ##\n";
cout<<"Select an option: ";
int option;
cin>>option;
}
if(strcmp(option, "1") == 0)
{
std::string strTurkey = "Happy Turkey Day! insanityclownZ\n";
cout<<"## Downloading m4 ! ##";
cout<<strTurkey;
}
else if(strcmp(option, "2") == 0)
{
cout<<"Billy says bye !\n";
}
else
{
cout<<"Invalid option dumbass! ";
}
cin.get();
cin.get();
return 0;
}
-
Code:
else
{
int option; // option is declared inside this else block
} // option goes out of scope here, option is no more
if(strcmp(option, "1") == 0) // option does not exist here.
-Prelude
-
So what do I do to continue making it exist?
I must put if inside the else?
I put it in there, and now I get a 43 C:\Documents and Settings\Reuben\My Documents\razor.cpp
passing `int' to argument 1 of `strcmp(const char *, const char *)' lacks a cast
error
-
make 'option' a char (or char array)
-
Thanks alot again. Now if I want Invalid option to show when that person press enter, what do I put?
-
if you move option to be local to main() and not an if/else and if you make option a char array, everything should work as it is. If you want to do something else, you will need to be more specific/descriptive of the goal.
-
Well, I want it to be like this:
When someone press enter, without pressing any letters, I want it to print "Invalid". I don't want it to close either.
Are there any exit commands too?