C ++错误主表达式之前
C++ Error Primary Expression Before
#include <iostream>
#include <string>
using namespace std;
string name;
string friend;
int gender;
int drive;
int main()
{
//Name prompt for future reference
cout << "Hello. I want to play a game. You'll be going on a";
cout << std::endl;
cout << "wild ride with it's own ups and downs.";
cout << std::endl;
cout << "To start out what is your name?";
cout << std::endl;
cin >> name;
//Determining Which Gender the player identifies with
cout << "Perfect " <<name;
cout << ". We shall ask a few more questions to determine";
cout << std::endl;
cout << "path will be best suited for you.";
cout << std::endl;
cout << "What is your gender?";
cout << std::endl;
cout << "If Male enter 1";
cout << std::endl;
cout << "If Female enter 2";
cout << std::endl;
cin >> gender;
cout << std::endl;
//Now we shall start the path determined by the chosen gender
if(gender == 1)
{cout << "Fantastic! You're a male so that means you are very simple. With that being said let us get started.";}
else
{cout << "Hmm... This seems to be a little difficult our systems indicate that putting you into situations seems a little bit more... complex. Never the matter. Let us get started!";}
cout << std::endl;
//Now the actual story begins.
if(gender == 2)
{cout << "You've been invited to a friends party. Although your mother doesn't";
cout << std::endl;
cout << "like you driving that far by yourself. What is your friend's name?";
cout << std::endl;
cin >> friend;
cout << std::endl;
cout << "They offer to drive you, but you can also drive yourself and risk";
cout << std::endl;
cout << "getting into trouble with your mother. What option shall you choose";
cout << std::endl;
cout << "If you want to drive yourself enter 1";
cout << std::endl;
cout << "If you want "<<friend;
//One of the problems Primary Experession Before <<friend
cout << " to drive you enter 2";
cout << std::endl;
cin >> drive;
cout << std::endl;}
if ((gender == 2) && (drive == 1))
{cout << std::endl;
cout << "You have chosen to drive yourself. You start up your car and";
cout << std::endl;
cout << "realize you don't have the address for your friends house.";
cout << std::endl;
cout << "You pull over at a nearby gas station to text " << friend;
cout << " and ask";
cout << std::endl;
cout << "her what the address is. Her reply to you is";
cout << std::endl;
cout << "Just come to my house. I'll drive you there.";
cout << std::endl;
cout << "You decide to push the issue of driving yourself.";
cout << std::endl;
cout <<friend" texts you the address and you put it into your GPS and start driving.";
cout << std::endl;
cout << "You make it to the party and beat "<<friend;
cout << " to the party";
cout << std::endl;
cout << "by five minutes. When she gets there she says that she doesn't";
cout << std::endl;
cout << "like the fact that you drove yourself.";
cout << std::endl;}
if ((gender == 2) && (drive == 2))
{cout << std::endl;
cout << "You ride with " <<friend;
cout << " and you have fun and crack";
cout << std::endl;
cout << "some jokes about your parents and boys";
cout << std::endl;
cout << "You two make it there and there are already a few other";
cout << std::endl;
cout << "people there";
cout << std::endl;}
if ((gender == 2) && (drive <= 2))
{cout << std::endl;
cout << "You are at the party and you go inside";
cout << std::endl;
cout << "your friends house with " <<friend;
cout << std::endl;}
return 0;
}
问题出在每次表达friend;出现它给了我一个错误。我试过用名字来建模;但它仍然行不通。我试过查找答案,但由于我是 C++ 的初学者,所以我无法理解其他人在问或说的任何内容
"The problem is each time the expression friend;
comes up it gives me an error."
friend
是c++语言的关键字。您不能将其用作变量名。
#include <iostream>
#include <string>
using namespace std;
string name;
string friend;
int gender;
int drive;
int main()
{
//Name prompt for future reference
cout << "Hello. I want to play a game. You'll be going on a";
cout << std::endl;
cout << "wild ride with it's own ups and downs.";
cout << std::endl;
cout << "To start out what is your name?";
cout << std::endl;
cin >> name;
//Determining Which Gender the player identifies with
cout << "Perfect " <<name;
cout << ". We shall ask a few more questions to determine";
cout << std::endl;
cout << "path will be best suited for you.";
cout << std::endl;
cout << "What is your gender?";
cout << std::endl;
cout << "If Male enter 1";
cout << std::endl;
cout << "If Female enter 2";
cout << std::endl;
cin >> gender;
cout << std::endl;
//Now we shall start the path determined by the chosen gender
if(gender == 1)
{cout << "Fantastic! You're a male so that means you are very simple. With that being said let us get started.";}
else
{cout << "Hmm... This seems to be a little difficult our systems indicate that putting you into situations seems a little bit more... complex. Never the matter. Let us get started!";}
cout << std::endl;
//Now the actual story begins.
if(gender == 2)
{cout << "You've been invited to a friends party. Although your mother doesn't";
cout << std::endl;
cout << "like you driving that far by yourself. What is your friend's name?";
cout << std::endl;
cin >> friend;
cout << std::endl;
cout << "They offer to drive you, but you can also drive yourself and risk";
cout << std::endl;
cout << "getting into trouble with your mother. What option shall you choose";
cout << std::endl;
cout << "If you want to drive yourself enter 1";
cout << std::endl;
cout << "If you want "<<friend;
//One of the problems Primary Experession Before <<friend
cout << " to drive you enter 2";
cout << std::endl;
cin >> drive;
cout << std::endl;}
if ((gender == 2) && (drive == 1))
{cout << std::endl;
cout << "You have chosen to drive yourself. You start up your car and";
cout << std::endl;
cout << "realize you don't have the address for your friends house.";
cout << std::endl;
cout << "You pull over at a nearby gas station to text " << friend;
cout << " and ask";
cout << std::endl;
cout << "her what the address is. Her reply to you is";
cout << std::endl;
cout << "Just come to my house. I'll drive you there.";
cout << std::endl;
cout << "You decide to push the issue of driving yourself.";
cout << std::endl;
cout <<friend" texts you the address and you put it into your GPS and start driving.";
cout << std::endl;
cout << "You make it to the party and beat "<<friend;
cout << " to the party";
cout << std::endl;
cout << "by five minutes. When she gets there she says that she doesn't";
cout << std::endl;
cout << "like the fact that you drove yourself.";
cout << std::endl;}
if ((gender == 2) && (drive == 2))
{cout << std::endl;
cout << "You ride with " <<friend;
cout << " and you have fun and crack";
cout << std::endl;
cout << "some jokes about your parents and boys";
cout << std::endl;
cout << "You two make it there and there are already a few other";
cout << std::endl;
cout << "people there";
cout << std::endl;}
if ((gender == 2) && (drive <= 2))
{cout << std::endl;
cout << "You are at the party and you go inside";
cout << std::endl;
cout << "your friends house with " <<friend;
cout << std::endl;}
return 0;
}
问题出在每次表达friend;出现它给了我一个错误。我试过用名字来建模;但它仍然行不通。我试过查找答案,但由于我是 C++ 的初学者,所以我无法理解其他人在问或说的任何内容
"The problem is each time the expression
friend;
comes up it gives me an error."
friend
是c++语言的关键字。您不能将其用作变量名。