i have looked at multiple tutorials including one sent to my by return 0 and my code says i have errors on line 63. it says choice undefined first use this function.
#include <windows.h>
#include <iostream>
#include <string>
#include <limits>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::numeric_limits;
using std::streamsize;
int main()
{
const int GOLD_PEICES = 900;
int crew, killed, survivors, enemy_army;
string leader, vp, enemy, galaxy, ship_name;
{
cout << "welcome to your space adventure \n";
cout << "please enter the following so that i can make your adventure \n\n";
cout << "enter a # under 900: " ;
cin >> crew;
cout << "enter a # under 802 and lower than the last # you chose : " ;
cin >> killed;
survivors = crew - killed;
cout << "enter your last name : " ;
cin >> leader;
cout << "enter the last name of an ex boyfriend/girlfriend : " ;
cin >> enemy;
cout << " enter the name of a pet you have or want : " ;
cin >> ship_name;
cout << "enter the funniest word you can think of : " ;
cin >> galaxy;
cout << "enter the last name of your best friend : " ;
cin >> vp;
enemy_army = crew * 3 / 2;
system("PAUSE");
cout << "making story please wait........." ;
_sleep(5000);
system("CLS");
}
// the story
cout << "The year was 2511.\n";
cout << "And the brand new ship, the " << ship_name << "-2 had just set sail. ";
cout << "its mission was to travel the 7 galaxies ";
cout << "and the first one was the most dangerous. ";
cout << "They were going to fly straight through the " << galaxy <<" ";
cout << "galaxy. general " << leader << " was the leader of the ship ";
cout << "and sgt. " << vp << " was 2nd in command ";
cout << "The ship was housing " << crew << " people. ";
cout << "the reason this galaxy was so dangerous is because of " << enemy << " ";
cout << "the giant multicolored space ape. " << enemy << " controles an army " ;
cout << "of " << enemy_army << " space chimpanzees. " ;
cout << "The mission was going good and with succesion. no one had even heard from " << enemy << ". ";
cout << "Just then the ship started shaking. it was a single blast from " << enemy << "'s portable zoo ship";
cout << " its all up to you general. what should we do???";
// first decision. choose to run, defend left, defend right, or defend front?
bool a = false, b = false, c = true, d = false;
cout << "\nif you choose to run press a\n ";
cout << "if you choose to defend left press b\n ";
cout << "if you choose to defend right press c\n " ;
cout << "and if you choose to defend front d\n " ;
cin >> choice;
switch (choice)
{
case 'a':
case 'A':
cout << "i say we should run. we cant overthrow " << enemy << ". " ;
cout << "as the ship turns around it starts to shake again... and again... and again. " ;
cout << "then there is an explosion in the engine room and the ship crashes " ;
break;
case 'b':
case 'B':
cout << "i say we defend the left. Hurry!! " ;
cout << "the chimps fought all angles of the ship but there were to many of them and they " ;
cout << "eventually attacked the right side enough to make the engine blow up. " ;
cout << "When it did the ship was stranded and even though the crew could fight back. eventually the crew ran out of ammo and " ;
cout << "the ship was destroyed. " ;
cout << " " ;
}
system("PAUSE");
}
Next, when posting blocks of code, use code block tag[code][/code]
Your issue at line 63 is because you never declared choice as a variable. I'm not entirely sure what you are doing with bool a, b, c, and d on line 58, you never use them.
On another note, I doubt you would want GOLD_PEICES (you misspelled pieces, btw) to be constant, because it should change as you loot enemies.
as you have probaly noticed i am new at this. i started on my bday jan. 7th.
uuummm gold pieces hasnt been used yet and it is supposed to be a constant but thanx anyway. can you further explain the code block tag because i dont really know what it is. and last on line 58 only one of them is going to get you to the next part of this program and all of the others will end in da ship crashing or do i still need to change it???
On line 63, you never declared choice as a variable.
cin >> choice;
makes no sense to the compiler, because it doesn't know what choice is. You never declared it.
Line 58 serves very little purpose, you are declaring variables a, b, c, and d, but you are never using them. By putting a in the apostrophes, 'a', on line 66 it makes it a character constant, and not a variable at all.
#include <iostream>
#include <cstdlib>
#include <string>
usingnamespace std;
int main()
{
int GOLD_PEICES = 900;
int crew, killed, survivors, enemy_army,choice;
string leader, vp, enemy, galaxy, ship_name;
cout <<"welcome to your space adventure \n";
cout <<"please enter the following so that i can make your adventure \n\n";
cout <<"enter a # under 900: " ;
cin >> crew;
cout <<"enter a # under 802 and lower than the last # you chose : " ;
cin >> killed;
survivors = crew - killed;
cout <<"enter your last name : " ;
cin >>leader;
cout <<"enter the last name of an ex boyfriend/girlfriend : " ;
cin >> enemy;
cout <<" enter the name of a pet you have or want : " ;
cin >> ship_name;
cout <<"enter the funniest word you can think of : " ;
cin >> galaxy;
cout <<"enter the last name of your best friend : " ;
cin >> vp;
enemy_army = crew * 3 / 2;
system("PAUSE");
system("cls");
cout << "making story please wait........." ;
cout << "The year was 2511.\n";
cout << "And the brand new ship, the " << ship_name << "-2 had just set sail. ";
cout << "its mission was to travel the 7 galaxies ";
cout << "and the first one was the most dangerous. ";
cout << "They were going to fly straight through the " << galaxy <<" ";
cout << "galaxy. general " << leader << " was the leader of the ship ";
cout << "and sgt. " << vp << " was 2nd in command ";
cout << "The ship was housing " << crew << " people. ";
cout << "the reason this galaxy was so dangerous is because of " << enemy << " ";
cout << "the giant multicolored space ape. " << enemy << " controles an army " ;
cout << "of " << enemy_army << " space chimpanzees. " ;
cout << "The mission was going good and with succesion. no one had even heard from " << enemy << ". ";
cout << "Just then the ship started shaking. it was a single blast from " << enemy << "'s portable zoo ship";
cout << " its all up to you general. what should we do???";
// first decision. choose to run, defend left, defend right, or defend front?
cout << "\nif you choose to run press 1\n ";
cout << "if you choose to defend left press 2\n ";
cout << "if you choose to defend right press 3\n " ;
cout << "and if you choose to defend front 4\n " ;
cin >> choice;
switch (choice)
{
case 1:
cout << "i say we should run. we cant overthrow " << enemy << ". " ;
cout << "as the ship turns around it starts to shake again... and again... and again. " ;
cout << "then there is an explosion in the engine room and the ship crashes " ;
break;
case 2:
cout << "i say we defend the left. Hurry!! " ;
cout << "the chimps fought all angles of the ship but there were to many of them and they " ;
cout << "eventually attacked the right side enough to make the engine blow up. " ;
cout << "When it did the ship was stranded and even though the crew could fight back. eventually the crew ran out of ammo and " ;
cout << "the ship was destroyed. " ;
cout << " " ;
}
system("pause");
};
uuuummmm i didnt really see anything that popped out as an error but on the last line (76) take out the ;. i think that might cause a problem but idk. its good i like it
I don't want to get you down, but if you're new to C++, you shouldn't be trying your hand at games yet. Maybe try something simple, like a guessing game or a simple card game. You might also want to try Project Euler to help your problem solving skills.