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
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
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.
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.
Thanks. Hm. I was just wondering why codes some have case and others have if and else? What does case do that is different?
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; }
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
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?