错误C2143:语法错误:缺少';'在'恒定'之前

时间:2011-04-05 15:05:34

标签: visual-c++

您好我正在尝试使用microsofts visual studio 2010制作基于文本的游戏唯一的问题是,当我制作一些函数时,它给了我这个错误,当我想运行它时出现错误C2143:语法错误:缺少';'在'常数'之前,我无法弄明白。这是c ++中的脚本

// Text Game.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdlib.h>

void ShowIntroduction ( void )
{
    printf( "Hello welcome to this text-based adventure game.\n" );
    printf( "In this adventure game we will run into many difficult situations\n" );
    printf( "1. A situation will present it's self\n" );
    printf( "2. You will be given some choices.\n" );
    printf( "3. You will need to make some choices.\n" );
    printf( "4. The result of your choice will be shown.\n" );
}
void ShowSituation1 ( void )
{
    printf( "\n\nYou are walking down a loney, dusty road.\n" );
    printf( "When you see a gem on the ground.\n" );
    printf( "It is bright and shiny!!\n" );
}
void ShowSituation2 ( void )
{
    printf( "\n\nThe cave entrance looks inviting.\n" );
    printf( "You are tempted to enter.\n" );
    printf( "It looks kind of dark.\n" );
}
void ShowSituation3 ( void )
{
    printf( "\nDo you want to keep going?\n" );
}
void ShowChoices1 ( void )
{
    printf( "\nHere are your choices\n" );
    printf( "1. Pick up the gem.\n");
    printf( "2. Kick the gem off the road.\n" );
    printf( "3. Stomp on the gem.\n" );
}
void ShowChoices2 ( void )
{
    printf( "\nHere are your choices.\n" );
    printf( "1. Run away\n" );
    printf( "2. Take a nap.\n" );
    printf( "3. Slowly enter the cave.\n" );
}
void ShowChoices3 ( void )
{
    printf( "\n1. Ya I ain't scared.\n" );
    printf( "2. No I need my mommy.\n" );
}
int GetChoice ( int min, int max)
{
    int Choice;

    do
    {
    printf( "Your choice? " );
    scanf( "%d", &Choice );
    }
    while( Choice < min || Choice > max );

    return( Choice );
}
void ShowResults1 ( int Choice )
{
    if( Choice == 1 )
    {
        printf( "\nYou pick up the gem and put it in your backpack.\n" );
        printf( "You start walking down the road when you see smoke coming from your backpack.\n" );
        printf( "Quickly you throw your bag off and jump down the hill just in time to escape the explosin from your bag.\n" );
        printf( "You continue to roll down the hill, when you finally stop you get up and find a cave.\n" );
    }
    else if( Choice == 2 )
    {
        printf( "\nThe gem flys off the road.\n" );
        printf( "You decide to see if you can find where it landed.\n" );
        printf( "When you reach the bottom you notice a cave.\n" );

    }
    else if( Choice == 3 )
    {
        printf( "\nThe gem sends you sky high.\n" );
        printf( "You hope that your health insurance is up to date.\n" );
        printf( "Lucky for you it was a nice grassy hill you landed on.\n" );
        printf( "You stand up to figure out where you are.\n" );
        printf( "You notice a cave.\n" );
    }
    else
    {
        printf( "\nThat wasn't a Choice you bozo.\n" );
        printf( "You are dead now!!\n" );
        exit (0);
    }
}
void ShowResults2 ( int Choice )
{
    if( Choice == 1 )
    {
        printf( "\nWhat a chicken.\n" );
        printf( "Looks like you need your mommy.\n" );
    exit 0;
    }
    else if( Choice == 2 )
    {   
        printf( "\nIt is night time when you awake.\n" );
        printf( "You get up and start walking but don't make it far.\n" );
        printf( "You were attacked by a pack of wolves.\n" );
    exit 0;
    }
    else if( Choice == 3 )
    {
        printf( "You enter the cave slowly.\n" );
        printf( "Your only light sorce is a lighter in your pocket.\n" );
        printf( "You find a torch on the wall, you get the torch lit.\n" );
    }
    else
    {
        printf( "\nThat wasn't a Choice you bozo.\n" );
        printf( "You are dead now!!\n" );
        exit (0);
    }
}
void ShowResults3 ( int Choice )
{
    if( Choice == 1 )
    {
        printf( "\nYou decide to keep going.\n" );

    }
    else if( Choice == 2 )
    {
        printf( "\nWhat a pussy you are!!\n" );
    exit 0;
    }
    else
    {
        printf( "\nThat wasn't a Choice you bozo.\n" );
        printf( "You are dead now!!\n" );
        exit (0);
    }
}





int _tmain(int argc, _TCHAR* argv[])
{
    int Choice;

    ShowIntroduction ();

    ShowSituation1 ();

    ShowChoices1 ();

    Choice = GetChoice ( 1,3 );

    ShowResults1 ( Choice );

    ShowSituation2 ();

    ShowChoices2 ();

    Choice = GetChoice ( 1,3 );

    ShowResults2 ( Choice );

    ShowSituation3 ();

    ShowChoices3 ();

    Choice = GetChoice ( 1,3 );

    ShowResults3 ( Choice );

    return 0;
}

1 个答案:

答案 0 :(得分:1)

它是exit(0),而不是exit 0

你可以很容易地缩小范围。另外请在提交之前检查帖子的格式:提问题页面上有一个预览窗格。