#include %26lt;iostream%26gt;
#include %26lt;string%26gt;
using namespace std;
const char Semi_colon = ';';
const string VERB1 = "guess";
int main ()
{
string firstLine;
int play;
int escape;
string guess;
int cl18=0; // make sure the semi-colon
int cl20=0; // make sure the semi-colon
string clue;
;int start=0;
start:
cout %26lt;%26lt; "This program was created by Amanda Harmony";
cout %26lt;%26lt; "Would you like to play?\n Press 1 for yes, and 0 for no.\n";
cin %26gt;%26gt; play;
if ( play == 1 )
{
goto cl1;
};
if ( play == 0 )
{
goto ender;
};
cl1:
cout %26lt;%26lt; "I am not real." %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
if ( guess == "Star Trek" )
{
cout %26lt;%26lt; "CORRECT!";
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
cin %26gt;%26gt; escape;
if ( escape == 0 )
{
goto cl1;
};
cl2:
cout %26lt;%26lt; "I take place in the future." %26lt;%26lt; endl;
cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
if (guess == "Star Trek")
{
cout %26lt;%26lt; "CORRECT!";
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
cin %26gt;%26gt; escape;
if ( escape == 0 )
{
goto cl2;
};
cl3:
cout %26lt;%26lt; "There is a whole new generation of me." %26lt;%26lt; endl;
cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
if (guess == "Star Trek")
{
cout %26lt;%26lt; "CORRECT!";
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
cin %26gt;%26gt; escape;
if ( escape == 0 )
{
goto cl3;
};
cl4:
cout %26lt;%26lt; "I take you to new places where no one has been before." %26lt;%26lt; endl;
cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
if (guess == "Star Trek")
{
cout %26lt;%26lt; "CORRECT!";
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n ";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
cin %26gt;%26gt; escape;
if ( escape == 0 )
{
goto cl4;
};
cl5:
cout %26lt;%26lt; "I have a doctor with me at all times." %26lt;%26lt; endl;
cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
if (guess == "Star Trek")
{
cout %26lt;%26lt; "CORRECT!";
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
cin %26gt;%26gt; escape;
if ( escape == 0 )
{
goto cl5;
};
cl6:
cout %26lt;%26lt; "Sometimes I can't believe my ears." %26lt;%26lt; endl;
cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
if (guess == "Star Trek")
{
cout %26lt;%26lt; "CORRECT!";
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
cin %26gt;%26gt; escape;
if ( escape == 0 )
{
goto cl6;
};
cl7:
cout %26lt;%26lt; "I have been around since 1965." %26lt;%26lt; endl;
cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
if (guess == "Star Trek")
{
cout %26lt;%26lt; "CORRECT!";
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
cin %26gt;%26gt; escape;
if ( escape == 0 )
{
goto cl7;
};
cl8:
cout %26lt;%26lt; "I am the story of a mission." %26lt;%26lt; endl;
cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
if (guess == "Star Trek")
{
cout %26lt;%26lt; "CORRECT!";
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n ";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
cin %26gt;%26gt; escape;
if ( escape == 0 )
{
goto cl8;
};
cl9:
cout %26lt;%26lt; "I have been on TV and the movies." %26lt;%26lt; endl;
cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
if (guess == "Star Trek")
{
cout %26lt;%26lt; "CORRECT!";
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n ";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
cin %26gt;%26gt; escape;
if ( escape == 0 )
{
goto cl9;
};
cl10:
cout %26lt;%26lt; "I see stars and planets scientists have never seen." %26lt;%26lt; endl;
cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;
cin %26gt;%26gt;guess;
if (guess == "Star Trek")
{
cout %26lt;%26lt; "CORRECT!";
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
cin %26gt;%26gt; escape;
if ( escape == 0 )
{
goto cl10;
};
cl11:
cout %26lt;%26lt; "I take about an hour at the time" %26lt;%26lt; endl;
cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
if (guess == "Star Trek")
{
cout %26lt;%26lt; "CORRECT!";
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n ";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
cin %26gt;%26gt; escape;
if ( escape == 0 )
{
goto cl11;
};
cl12:
cout %26lt;%26lt; "My ships don't travel by sea." %26lt;%26lt; endl;
cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
if (guess == "Star Trek")
{
cout %26lt;%26lt; "CORRECT!";
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
cin %26gt;%26gt; escape;
if ( escape == 0 )
goto cl12;
};
cl13:
cout %26lt;%26lt; "I know asians, African-Americans and Russians." %26lt;%26lt; endl;
cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
if (guess == "Star Trek")
{
cout %26lt;%26lt; "CORRECT!";
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
cin %26gt;%26gt; escape;
if ( escape == 0 )
{
goto cl13;
};
cl14:
cout %26lt;%26lt; "John Belshi and Dan Ackroyd made fun of me." %26lt;%26lt; endl;
cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
if (guess == "Star Trek")
{
cout %26lt;%26lt; "CORRECT!";
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
cin %26gt;%26gt; escape;
if ( escape == 0 )
{
goto cl14;
};
cl15:
cout %26lt;%26lt; "Although not my business my interprise keeps me going." %26lt;%26lt; endl;
cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
if (guess == "Star Trek")
{
cout %26lt;%26lt; "CORRECT!";
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n ";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
cin %26gt;%26gt; escape;
if ( escape == 0 )
{
goto cl15;
};
cl16:
cout %26lt;%26lt; "I like to keep my own space." %26lt;%26lt; endl;
cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
if (guess == "Star Trek")
{
cout %26lt;%26lt; "CORRECT!";
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
{
cin %26gt;%26gt; escape;
if ( escape == 0 )
{
goto cl16;
};
cl17:
cout %26lt;%26lt; "I have a cult following." %26lt;%26lt; endl;
cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
if (guess == "Star Trek")
{
cout %26lt;%26lt; "CORRECT!";
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n ";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
{
cin %26gt;%26gt; escape;
if ( escape == 0 )
{
goto cl17;
};
cl18: cout %26lt;%26lt; "Certain crystals empower me." %26lt;%26lt; endl;
cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
if (guess == "Star Trek")
{
cout %26lt;%26lt; "CORRECT!";
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
{
cin %26gt;%26gt; escape;
if ( escape == 0 )
{
goto cl18;
};
cl19:
cout %26lt;%26lt; "A person names data resides on this ship." %26lt;%26lt; endl;
cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
if (guess == "Star Trek")
{
cout %26lt;%26lt; "CORRECT!";
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess, again press 1. To quit, press 0.\n";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
{
cin %26gt;%26gt; escape;
if ( escape == 0 )
{
goto cl9;
};
cl20:
cout %26lt;%26lt; "Kirk vs. Picard." %26lt;%26lt; endl;
cout %26lt;%26lt; "Guess?" %26lt;%26lt; endl;
cin %26gt;%26gt; guess;
if (guess == "Star Trek")
{
cout %26lt;%26lt; "CORRECT!";
}
if (guess != "Star Trek")
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0.\n";
cout %26lt;%26lt; "Guess again?";
cin %26gt;%26gt; guess;
firstLine = "Star Trek";
{
cin %26gt;%26gt; escape;
if ( escape == 0 )
{
goto cl20;
};
ender:
return 0;
}
C++ I only have one error, I have the closing bracket at the end so what is wrong? Error C1004?
I'm not sure why you are doing it with "GOTO". I have re-implemented it for you, and it works with one loop, much easier to understand. I compiled and ran it, I'm pretty sure it does what you want.
It creates a list of clues, and each incorrect guess provides you with a different clue. If you guess it correctly, it ends.
[CODE START]
#include %26lt;iostream%26gt;
#include %26lt;string%26gt;
#include %26lt;vector%26gt;
using namespace std;
int main()
{
const string correctAnswer = "startrek";
const string guess = "Guess?";
int keepGoing;
string input;
//***
// Do we really want to play?
//***
cout %26lt;%26lt; "This program was created by Amanda Harmony";
cout %26lt;%26lt; "Would you like to play?\n Press 1 for yes, and 0 for no.\n";
cin %26gt;%26gt; keepGoing;
if (keepGoing == 0)
{
cout %26lt;%26lt; "Goodbye." %26lt;%26lt; endl;
return 0;
}
//***
// Establish our list of clues
// We should put this in a method but i'm being lazy.
//***
std::vector%26lt;string%26gt; clues;
string currentQ = "I am not real.";
clues.push_back(currentQ);
currentQ = "I take place in the future.";
clues.push_back(currentQ);
currentQ = "There is a whole new generation of me.";
clues.push_back(currentQ);
currentQ = "I take you to new places where no one has been before.";
clues.push_back(currentQ);
currentQ = "I have a doctor with me at all times.";
clues.push_back(currentQ);
currentQ = "Sometimes I can't believe my ears.";
clues.push_back(currentQ);
currentQ = "I have been around since 1965.";
clues.push_back(currentQ);
currentQ = "I am the story of a mission.";
clues.push_back(currentQ);
currentQ = "I have been on TV and the movies.";
clues.push_back(currentQ);
currentQ = "I see stars and planets scientists have never seen.";
clues.push_back(currentQ);
currentQ = "I take about an hour at the time";
clues.push_back(currentQ);
currentQ = "My ships don't travel by sea.";
clues.push_back(currentQ);
currentQ = "I know asians, African-Americans and Russians.";
clues.push_back(currentQ);
currentQ = "John Belshi and Dan Ackroyd made fun of me.";
clues.push_back(currentQ);
currentQ = "Although not my business my interprise keeps me going.";
clues.push_back(currentQ);
currentQ = "I like to keep my own space.";
clues.push_back(currentQ);
currentQ = "I have a cult following.";
clues.push_back(currentQ);
currentQ = "Certain crystals empower me.";
clues.push_back(currentQ);
currentQ = "A person names data resides on this ship.";
clues.push_back(currentQ);
currentQ = "Kirk vs. Picard.";
clues.push_back(currentQ);
for (int i=0; i %26lt; clues.size(); ++i) //let's go through all the clues
{
cout %26lt;%26lt; clues[i] %26lt;%26lt; endl;
cout %26lt;%26lt; guess %26lt;%26lt; endl;
cin %26gt;%26gt; input;
if (0 == input.compare(correctAnswer)) //star trek
{
cout %26lt;%26lt; "CORRECT!" %26lt;%26lt; endl;
return 0;
}
else
{
cout %26lt;%26lt; "INCORRECT To guess again, press 1. To quit, press 0." %26lt;%26lt; endl;
cin %26gt;%26gt; keepGoing;
if (keepGoing == 0)
{
return 0;
}
}
}
cout %26lt;%26lt; "Sorry, game over!" %26lt;%26lt; endl;
return 0;
}
[CODE END]
Reply:phew..
im glad im not taking that course..
OMGWTF..
im taking comp eng'g..
lol..
too bad just a freshmen..^^,
cant help..
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment