Write a program which can be used to calculate bonus points to given scores in the range [1..9] according to the following rules:
If the score is between 1 and 3, the bonus points is the score multiplied by 10
If the score is between 4 and 6, the bonus points is the score multiplied by 100
If the score is between 7 and 9, the bonus points is the score multiplied by 1000
For invalid scores there are no bonus points (0) Your program must make use of 2 parallel arrays – one to store the scores and the other to store the bonus points. You need to make provision for 5 scores (and bonus points) that will need to be stored. For this program implement the following methods and use these methods in your solution (do not change the method declarations):
static void getScores(int[] scores)
static void calcBonus(int[] scores, int[] bonusPoints)
static void displayAll(int[] scores, int[] bonusPoints)
using System;
namespace Program
{
class Program
{
static void getScores(int[] scores)
{
for (int i = 0; i < scores.Length; i++)
{
Console.Write("Enter score {0}:", i+1);
scores[i] = int.Parse(Console.ReadLine());
}
}
static void calcBonus(int[] scores, int[] bonusPoints)
{
for (int i = 0; i < scores.Length; i++)
{
switch (scores[i])
{
case 1:
case 2:
case 3:
bonusPoints[i] = scores[i] * 10;
break;
case 4:
case 5:
case 6:
bonusPoints[i] = scores[i] * 100;
break;
case 7:
case 8:
case 9:
bonusPoints[i] = scores[i] * 1000;
break;
default:
bonusPoints[i] = 0;
break;
}
}
}
static void displayAll(int[] scores, int[] bonusPoints)
{
for (int i = 0; i < scores.Length; i++)
{
Console.WriteLine("Score={0}, Bonus points={1}", scores[i], bonusPoints[i]);
}
}
static void Main(string[] args)
{
int[] scores = new int[5];
int[] bonusPoints = new int[5];
getScores(scores);
calcBonus(scores, bonusPoints);
displayAll(scores, bonusPoints);
}
}
}
Comments
Leave a comment