dimanche 3 novembre 2019

1 unexpected test outcome out of 10

Pepi calls you and asks you to write a program that prints a specific result on the console. After several soccer matches, he noticed that between certain minutes a player always misses a penalty, receives a yellow card, scores a goal, receives a free-kick or misses a corner. Sign in The console reads 2 lines: • First row - minutes - integer positive in the interval [0… 10000] • Second line - player name - text Exit In the first line, print: • "Match has just started!" - if the minutes are 0. • "First half time." - if the minutes are less than 45. • "Second half time." - if the minutes are 45 or more. In the following line print: • If the minutes are between 1 and 10 inclusive: "{player name} missed a penalty." o If at the same time the minutes are an even number, print:                "{player name} was injured after the penalty." • If the minutes are greater than 10 and less than or equal to 35: "{player name} received yellow card." o If at the same time the minutes are an odd number, print:                             "{player name} got another yellow card." • If the minutes are greater than 35 and less than 45: "{Player Name} SCORED A GOAL !!!" • If the minutes are greater than 45 and less than or equal to 55. "{player name} got a freekick." o If at the same time the minutes are an even number, print:                              "{player name} missed the freekick." • If the minutes are greater than 55 and less than or equal to 80. "{player name} missed a shot from corner." o If at the same time the minutes are an odd number, print:                             "{player name} has been changed with another player." • If the minutes are greater than 80 and less than or equal to 90: "{Player Name} SCORED A GOAL FROM PENALTY !!!" Example input and output Login Exit Explanation 85 Harry Kane Second half time. Harry Kane SCORED A GOAL FROM PENALTY !!! The minutes are over 45 and we print the first line, then we see that they are in the range of 80 to 90 and we print the second line. 10 Messi First half time. Messi missed a penalty. Messi was injured after the sentence. 25 Ronaldo First half time. Ronaldo received a yellow card. Ronaldo got another yellow card.

I did the program, but 1 test input out of 10 gave out a wrong answer. I don't know the input itself, but if you helped, it would mean a lot.

          string name;
          minutes = Convert.ToInt32(Console.ReadLine());
          name = Console.ReadLine();
              if (minutes == 0) Console.WriteLine("Match has just began!");
              else if (minutes < 45) Console.WriteLine("First half time.");
              else Console.WriteLine("Second half time.");
              if (minutes == 0) placeholder = 0;
              else if (minutes > 0 && minutes <= 10) { Console.WriteLine(name + " missed a penalty."); if (minutes % 2 == 0) Console.WriteLine(name + " was injured after the penalty."); }
              else if (minutes <= 35) { Console.WriteLine(name + " received yellow card."); if (minutes % 2 != 0) Console.WriteLine(name + " got another yellow card."); }
              else if (minutes <= 45) Console.WriteLine(name + " SCORED A GOAL !!!");
              else if (minutes <= 55) { Console.WriteLine(name + " got a freekick."); if (minutes % 2 == 0) Console.WriteLine(name + " missed the freekick."); }
              else if (minutes <= 80) { Console.WriteLine(name + " missed a shot from corner."); if (minutes % 2 != 0) Console.WriteLine(name + " has been changed with another player."); }
              else if (minutes <= 90) Console.WriteLine(name + " SCORED A GOAL FROM PENALTY !!!");

Aucun commentaire:

Enregistrer un commentaire