2016-07-14 4 views
0

テストスコアを取得するためにコンソールプログラムを作成し、最大値を0より大きく、取得した最高得点以上に設定する必要がありますが、 "maxscore"の検証には拘束されています。ユーザからの入力を確認する

これは私がこれまで持っているものです。

int[] score = new int[5]; 
int highScore = 0; 
int sum = 0; 
int ave = 0; 

//Requests the user to input 5 numbers 
Console.WriteLine("Please enter 5 test scores:"); 

//Obtains the input and sets the highScore as well as the sum for all the number entered 

for (int i = 0; i < 5; i++) 
{ 
    score[i] = Int32.Parse(Console.ReadLine()); 
    if (i > highScore) 
    { 
     highScore = i; 
     sum += score[i]; 
    } 
} 

//Requests the user to enter the max score 
Console.WriteLine("Please enter the max score:"); 
int maxScore = Int32.Parse(Console.ReadLine()); 
+0

という名前の配列内のスコアの実際の値である間、あなたは、ユーザーが最大を知っていることを検証したいです彼がすでに提供している5つの数字の間の数字? – user3185569

+0

あなたがスコア[i]の代わりにiをチェックした場合 – User1234

+0

このプログラムは意味がありません。また、スタックオーバーフローは無料のコーディングサービスではありません。 – aadarshsg

答えて

3

iの代わりscore[i]highScoreを比較するときにあなたが間違いを持っ​​ています。そして、あなたもhighScore = score[i]でなければなりません。

1

インデックスiとスコアscore[i]を区別する必要があります。 iを使用すると、配列要素からインデックスとして使用しているカウンタ、score[i]score

for (int i = 0; i < 5; i++) 
{ 
    score[i] = Int32.Parse(Console.ReadLine()); 
    if (score[i] > highScore) 
    { 
     highScore = score[i]; 
     sum += score[i]; 
    } 
} 
関連する問題