Thread: Option undeclared?

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    43

    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;
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    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
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    43
    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
    Last edited by trenzterra; 11-28-2002 at 09:06 PM.

  4. #4
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176
    make 'option' a char (or char array)

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    43
    Thanks alot again. Now if I want Invalid option to show when that person press enter, what do I put?

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    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.

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    43
    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?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM