I have just started to learn c++ so my code might not be the cleanest....Anyways, when I try to answer the "what do you want to do" question as soon as I press enter it ends the program.
#include <iostream> //for using cout
#include <unistd.h> //lets the program wait
#include <string> //allows strings
usingnamespace std; //for using cout
void HOME(){
//layout of the player home
cout<<"Welcome to Your home\n";
cout<<"There is a treasure chest by the window, type 'T' to see whats inside of it.\n";
cout<<"There is a bag by the front door, to access it type 'B'.\n";
cout<<"There is a closet door to your left, type 'C' to access it.\n";
cout<<"The door that leads outside is to your right, type 'D' to go through it.\n";
sleep(2);
cout<<"What would you like to do?\n";
}
void CHESTLVL1(){
cout<<"There is nothing in the chest"<<endl;
}
void BAGLVL1(){
cout<<"There is a notebook in the bag.\n";
sleep(1);
cout<<"Would you like to look at it? Y or N.\n";
}
void CLOSETLVL1(){
cout<<"There is a leather jacket and a motor cycle helmet.\n";
sleep(1);
cout<<"Do you want to take the leather jacket and helmet? Y or N.\n";
}
void NOTEBOOKLVL1(){
cout<<"*You flip through the notebook*";
cout<<"There are multiple drawings of mountains and planets.\n";
cout<<"Maybe you can fill this notebook with more stuff?\n";
}
int main(){
int hh1ans;
int bh1ans;
int ch1ans;
cout<<"Welcome to Terraneous! This is a place like no other! You can be what ever you chose to be. Though, be weary your choices can be good or bad."<<endl; //introduction
sleep(2); //waits for 2 senconds
string name; //to get player name
cout<<"What is your name? ";
getline(cin, name);
cout<<"Hello "<<name<<"!\n";
sleep(0.5);
HOME();
cin>>hh1ans;
if (hh1ans=='T'|| hh1ans=='t'){
CHESTLVL1();
sleep(3);
HOME();
}elseif (hh1ans=='B'||hh1ans=='b'){
BAGLVL1();
cin>>bh1ans;
if (bh1ans=='Y'||bh1ans=='y'){
NOTEBOOKLVL1();
sleep(9);
HOME();
}
else (bh1ans=='N'||bh1ans=='n');{
HOME();
}
}elseif (hh1ans=='C'||hh1ans=='c'){
CLOSETLVL1();
cin>>ch1ans;e
if (ch1ans=='Y'||ch1ans=='y'){
cout<<"You take the leather jacket!";
}else (ch1ans=='N'||ch1ans=='n');{
HOME();
}
}
}