2015-05-26 2 views
-25

Я делаю программу для имитации игрового шоу, случайным образом. Программа выбирает 1 из трех дверей для того, чтобы приз был скрыт случайно. Компьютер выбирает дверь, чтобы посмотреть, выиграла она или нет. Это зацикливается более 10000 раз, чтобы увидеть, сколько раз я выигрываю, если я изменю свой выбор или не изменю его.Где синтаксические ошибки, которые я получаю?

Я получаю кучу синтаксисом

#include <path-spec> 
#include <stdio.h> 
#include <time.h> 

void count(Status result, Door* pLast_pick, Door* pPick, int* pWin_unchanged, int* pWin_changed); 

void randomize_door(Door* pJackpot); 

void pick_door(Door* pPick); 

Status check(Door* pPick, Door* pJackpot); 

enum status {WIN=1,LOSE}; 

enum door { FIRST=1, SECOND, THIRD }; 

typedef enum door Door; 
typedef enum status Status; 

int main(int argc, char* argv[]){ 
    int i = 0; 
    srand(time); 
    Status result; 
    Status* pResult = &result ; 
    Door jackpot, pick, last_pick=NULL; 
    Door* pJackpot = &jackpot, * pPick=&pick, *pLast_pick; 
    int win_unchanged = 0, win_changed=0; 
    int* pWin_unchanged = &win_unchanged, *pWin_changed=&win_changed; 

    while (i < 10000){ 
     last_pick = NULL; 
     randomize_door(pJackpot); 
     pick_door(pPick); 
     result = check(pPick, pJackpot); 
     count(result, pLast_pick, pPick, pWin_unchanged, pWin_changed); 

     i++; 
    } 

    printf("Wins when changed choice: %d , wins when choice is unchanged: %d", win_changed, win_unchanged); 
    return 0; 
} 

void randomize_door(Door* pJackpot){ 

    *pJackpot = rand() % 3 + 1; 
} 

void pick_door(Door* pPick){ 

    *pPick = rand() % 3 + 1; 
} 

Status check(Door* pPick, Door* pJackpot){ 
    if (*pPick == *pJackpot){ 
     return WIN; 
    } 
    else{ 
     return LOSE; 
    } 
} 

void count(Status result, Door* pLast_pick, Door* pPick, int* pWin_unchanged, int* pWin_changed) { 
    if (*pLast_pick == *pPick){ 
     if (result == WIN){ 
      *pWin_unchanged++; 
     } 
    } 
    else{ 
     if (result == WIN){ 
      *pWin_changed++; 
     } 
    } 

    *pLast_pick = *pPick; 
} 

Ниже приведены ошибки и какие строки его случающиеся в. большинство из них забыли } или ;, что не имеет никакого смысла в заголовке функции.

1>------ Build started: Project: Program4.1, Configuration: Debug Win32 ------ 
1> daily4.c 
daily4.c(4): error C2146: syntax error : missing ')' before identifier 'result' 
daily4.c(4): error C2061: syntax error : identifier 'result' 
daily4.c(4): error C2059: syntax error : ';' 
daily4.c(4): error C2059: syntax error : ',' 
daily4.c(4): error C2059: syntax error : ')' 
daily4.c(6): error C2143: syntax error : missing ')' before '*' 
daily4.c(6): error C2143: syntax error : missing '{' before '*' 
daily4.c(6): error C2059: syntax error : ')' 
daily4.c(8): error C2143: syntax error : missing ')' before '*' 
daily4.c(8): error C2143: syntax error : missing '{' before '*' 
daily4.c(8): error C2059: syntax error : ')' 
daily4.c(10): error C2061: syntax error : identifier 'check' 
daily4.c(10): error C2059: syntax error : ';' 
daily4.c(10): error C2143: syntax error : missing ')' before '*' 
daily4.c(10): error C2143: syntax error : missing '{' before '*' 
daily4.c(10): error C2143: syntax error : missing ';' before '*' 
daily4.c(10): error C2059: syntax error : ')' 
daily4.c(16): error C2370: 'Door' : redefinition; different storage class 
daily4.c(10) : see declaration of 'Door' 
daily4.c(21): warning C4013: 'srand' undefined; assuming extern returning int 
daily4.c(24): error C2146: syntax error : missing ';' before identifier 'jackpot' 
daily4.c(24): error C2065: 'jackpot' : undeclared identifier 
daily4.c(24): error C2065: 'pick' : undeclared identifier 
daily4.c(24): error C2065: 'last_pick' : undeclared identifier 
daily4.c(24): warning C4047: '=' : 'int' differs in levels of indirection from 'void *' 
daily4.c(25): error C2297: '*' : illegal, right operand has type 'int *' 
daily4.c(25): error C2065: 'jackpot' : undeclared identifier 
daily4.c(25): error C2065: 'pick' : undeclared identifier 
daily4.c(25): warning C4047: '=' : 'int' differs in levels of indirection from 'int *' 
daily4.c(25): error C2065: 'pLast_pick' : undeclared identifier 
daily4.c(25): error C2100: illegal indirection 
daily4.c(30): error C2065: 'last_pick' : undeclared identifier 
daily4.c(30): warning C4047: '=' : 'int' differs in levels of indirection from 'void *' 
daily4.c(31): warning C4013: 'randomize_door' undefined; assuming extern returning int 
daily4.c(32): warning C4013: 'pick_door' undefined; assuming extern returning int 
daily4.c(33): warning C4013: 'check' undefined; assuming extern returning int 
daily4.c(34): warning C4013: 'count' undefined; assuming extern returning int 
daily4.c(34): error C2065: 'pLast_pick' : undeclared identifier 
daily4.c(43): error C2143: syntax error : missing ')' before '*' 
daily4.c(43): error C2143: syntax error : missing '{' before '*' 
daily4.c(43): error C2059: syntax error : ')' 
daily4.c(43): error C2054: expected '(' to follow 'pJackpot' 
daily4.c(48): error C2143: syntax error : missing ')' before '*' 
daily4.c(48): error C2143: syntax error : missing '{' before '*' 
daily4.c(48): error C2059: syntax error : ')' 
daily4.c(48): error C2054: expected '(' to follow 'pPick' 
daily4.c(53): error C2143: syntax error : missing ')' before '*' 
daily4.c(53): error C2143: syntax error : missing '{' before '*' 
daily4.c(53): error C2143: syntax error : missing ';' before '*' 
daily4.c(53): error C2059: syntax error : ')' 
daily4.c(53): error C2054: expected '(' to follow 'pJackpot' 
daily4.c(62): error C2143: syntax error : missing ')' before '*' 
daily4.c(62): error C2081: 'Door' : name in formal parameter list illegal 
daily4.c(62): error C2143: syntax error : missing '{' before '*' 
daily4.c(62): error C2143: syntax error : missing ';' before '*' 
daily4.c(62): error C2059: syntax error : 'type' 
daily4.c(62): error C2059: syntax error : ')' 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 
+5

ошибки ясно показаны в стеке ошибок! – tharif

+0

Я знаю, что они говорят мне эры. но этих ошибок просто не существует. –

+0

Сначала вам нужно определить 'enum', а затем использовать их в объявлении функции. Вы изменили порядок. –

ответ

2

образец исправить

#include <stdio.h> 
#include <time.h> 
#include <stdlib.h> //for srand 

//enum and typedef defined prior to use 
enum status {WIN=1,LOSE}; 
enum door { NONE, FIRST=1, SECOND, THIRD };//Define NONE instead of NULL 

typedef enum door Door; 
typedef enum status Status; 


void count(Status result, Door* pLast_pick, Door* pPick, int* pWin_unchanged, int* pWin_changed); 
void randomize_door(Door* pJackpot); 
void pick_door(Door* pPick); 
Status check(Door* pPick, Door* pJackpot); 

int main(int argc, char* argv[]){ 
    int i = 0; 
    Status result; 
    Status* pResult = &result ; 
    Door jackpot, pick, last_pick=NONE; 
    Door* pJackpot = &jackpot, * pPick=&pick, *pLast_pick; 
    int win_unchanged = 0, win_changed=0; 
    int* pWin_unchanged = &win_unchanged, *pWin_changed=&win_changed; 

    srand(time(NULL));//If you use the equivalent of the C89 compiler can not be mixed the declaration statement and execution statements. 

    ... 
+1

Пожалуйста, объясните, что вы исправили и почему. – dimo414

+2

@ dimo414 прочитал мой комментарий. – BLUEPIXY

Смежные вопросы