2011-08-13 11 views
-2

私はC++を学んでおり、カード販売店プログラムを書いています。私は私のコードをコンパイルし、私はこれらのエラーを取得する場合:これらのエラーは何ですか?どうすれば修正できますか?

dealer3.cpp:12: error: expected initializer before ‘int’ 
dealer3.cpp:33: error: expected constructor, destructor, or type conversion before ‘=’ token 
dealer3.cpp:34: error: expected constructor, destructor, or type conversion before ‘=’ token 
dealer3.cpp:35: error: expected constructor, destructor, or type conversion before ‘=’ token 
dealer3.cpp:36: error: expected constructor, destructor, or type conversion before ‘=’ token 
dealer3.cpp:37: error: expected constructor, destructor, or type conversion before ‘<<’ token 
dealer3.cpp:38: error: expected declaration before ‘}’ token 

、ここでは私のコードは

ある
#include<iostream> 
#include<time.h> 
#include<stdlib.h> 
#include<cmath> 

using namespace std; 

int randn(int n); 
void draw(); 
int uni(int n); 
char *suits[4]={"Hearts","Diamonds","spades","clubs"}; 
char *ranks[13]={"ace","two","three","four","five","six","seven","eight","nine","ten","jack","queen","king"}; 
int drawn[52]; 
int remaining=52; 
int main() { 
    int n; 
    int i; 
    srand(time(NULL)); 
    while(1) { 
     cout<<"enter number of cards to draw"<<endl; 
     cin>>n; 
     if (n==0) break; 

for (i=1; i<=n; i++) 
    draw(); 
} 

    return 0; 
} 
int r; 
int s; 
int n; 
int card; 
n=randn(remaining--); 
card=uni(n); 
    r=card%13; 
    s=card/13; 
    cout<<ranks[r]<<" of "<<suit[s]<<endl; 
} 
int uni(int n) 
{ 
int i=0; 
while (drawn[i]) 
    i++; 
while (n-->0){ 
    i++; 
while (drawn[i]) 
    i++; 
} 
card_drawn([i])=true; 
return i; 
} 
int randn (int n){ 
return rand()%n; 
} 

これはなぜでしょうか?

+0

あなたの質問は何ですか?エラーメッセージを読んだことがありますか? –

+0

はい私はエラーを読んだが、アンダーアンダーで何をするのかわからない –

+2

コードを正しくインデントすることから始めてください。 – jweyrich

答えて

6

実際には、コードをインデントすると、中括弧でいくつかのエラーが表示されるため、問題を解決する(またはソリューションを非常に明白にする)良いケースです。あなたはそこに属していない関数の外にあるいくつかのコード行を持っています。

あなたのためのいくつかの書式設定のヒント:

  • インデント(通常は4)のスペースの一定量のコードのネストされた各ブロック。
  • すべての機能の後に空白行を残します。
  • 関数の新しいブロックを開くとき、またはfor - 、while-またはif-statement(リストが続く)を開くときに、一貫して(コード全体で同じスタイル)開き括弧を置くように注意してください。
  • ブロックを閉じるブラケットが、ブロックを開いたステートメント/ブラケットと同じインデントレベルにあることを確認してください。

ほとんどのIDEには、自動的に書式設定を修正するオプションがあります(特にインデント)。

+0

うわー私はsupidですおかげで病気を試してください –

+0

Im C++ noob hanks so much –

+2

そしてひとつは、ブラケットスタイルの良さと別のものの良さを宣言しています。あなたはその議論がどのくらい長く続いているのか、それが完全に解決されていないと、永遠に残っていると思いますか? ;-) –

1

ブレースがありません。そして、次の声明は地球上の空間に入ります -

n=randn(remaining--); 
// ... 
関連する問題