Thread: Need some help with Dev C++ if and elses

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    12

    Need some help with Dev C++ if and elses

    Hey I just started computer programming and our teacher wants us to make a mud game using if and else but I am completely lost. I was wondering if anyone had any suggestions to help me get started? Thanks

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Lesson 2: If statements C++. You may also want to read some of the other tutorials there as well for actually making a mud type game.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    12
    Okay, thanks so much. Also do you have any tips on keeping the ifs and elses in order while I do it?

  4. #4
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by Rag View Post
    Okay, thanks so much. Also do you have any tips on keeping the ifs and elses in order while I do it?
    Proper indentation, especially with regards to placements of your braces.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  5. #5
    Registered User
    Join Date
    Sep 2011
    Posts
    12
    Thanks. Hm. I was just wondering why codes some have case and others have if and else? What does case do that is different?

  6. #6
    Registered User
    Join Date
    Sep 2011
    Posts
    12
    This is what I have so far (Not much at all... Sort of the structure a little bit I guess... Still trying to figure out where things go, how to fit answers in after the ifs and elses.:

    Code:
    #include <cstdlib> 8 if 8 else
    #include <iostream>
    #include <string.h>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    
        string name;
        int a, b, c;
        cout<<"Welcome to the Dungeon of Doom."<<endl<<endl;
        cout<<"Please enter your name."<<endl<<endl;
        cin>>name;
        cout<<endl;
        cout<<"Welcome, "<<name<<" to the Dungeon of Doom."<<endl<<endl;
        cout<<"You are walking down a dusty, dark forbidding walkway when you reach a set of two doors. You hearing wailing from one door and silence from the other. Which one do you choose? Enter 1 for the wailing door, and 2 for the silent one."<<endl;
        cin>>a;
        if (a==1)
           {
                 cout<<"You chose the right door! You see a guard punishing a wailing prisnor, but because he is busy he does not notice you which allows you to sneak by."<<endl;
                 cout<<"Once you leave the room, you walk down another dark hallway with cages on both side of you. You reach a choice to enter two cages, which one do you choose? The one with the skinny old man sleeping or the one with a forbidding six foot four man. Choose 1 for the old man and 2 for the forbidding one."<<endl;
                 cin>>a;
                 if (a==1)
                    {
                          if
                          else
                    }
                 else 
                      {
                          if
                          else
                      }
           }
        else 
             {
                      
                 cout<<"    "endl;
                 cin>>
                 if (a==1)
                    {
                          if
                          else
                    }
                 else 
                      {
                          if
                          else
                      }
          
             }
        
        
        
        system("PAUSE");
        return EXIT_SUCCESS;
    }

  7. #7
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by Rag View Post
    Thanks. Hm. I was just wondering why codes some have case and others have if and else? What does case do that is different?
    The switch case allows you to handle multiple possibilites easier rather than a long chain of if-else's. You can read through Lesson 5 - Switch Case
    Quote Originally Posted by Rag View Post
    This is what I have so far (Not much at all... Sort of the structure a little bit I guess... Still trying to figure out where things go, how to fit answers in after the ifs and elses.:
    Some pointers, you can reuse variables so there probably is no need for int a,b,c there. Also your variable names should be more descriptive as to there meaning, such as int userchoice. Also there is no reason for you to have included cstdlib here, and no reason I can think of that you will need to use it for this. EDIT: and it should be #include <string>, drop the .h [/EDIT]

    As for this project, how much C++ have you been taught? Do you know about file operations, arrays, functions, andything about the STL besides std::string?
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  8. #8
    Registered User
    Join Date
    Sep 2011
    Posts
    12
    Quote Originally Posted by AndrewHunter View Post
    The switch case allows you to handle multiple possibilites easier rather than a long chain of if-else's. You can read through Lesson 5 - Switch Case

    As for this project, how much C++ have you been taught? Do you know about file operations, arrays, functions, andything about the STL besides std::string?
    Um. I have been taught int and double and the string variable.... *sigh* dev c++ makes no sense to me D:

  9. #9
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by Rag View Post
    Um. I have been taught int and double and the string variable.... *sigh* dev c++ makes no sense to me D:
    Well, then just continue down the path that you are implementing; if you are only allowed to use an if-else chain.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using someone elses computer
    By Liger86 in forum Tech Board
    Replies: 4
    Last Post: 04-16-2003, 05:52 PM