Wednesday, 24 April 2013

TechnoSoft, a leading software company, has developed an application for maintaining the scores of games in a video game parlor. If the new score is greater than the stored top score, the following program should interchange the values of the variables Top_score and New_score. However, the program does not generate the desired output. Identify the error in the following program and write the correct code: using System; class Interchange { int Top_score; int New_score; int Temp; void Swap() { Top_score=5; New_score=10; Temp=top_score; New_score=Top_score; Top_score=New_score; } void Display() { Console.WriteLine("The new value of top score is:"); Console.WriteLine(Top_score); Console.WriteLine("The old value of top score was:"); Console.WriteLine(New_score); } static void Main() { Interchange I1; I1.Swap(); I1.Display(); Console.ReadLine(); } } (Duration: 25 min)


  using System;
   class Interchange
 {
   
      int Top_score;
      int New_score;
      int Temp;
      void swap()
 {
         
        Top_score=5;
        New_score=10;
        Temp=Top_score;
        Top_score=New_score;
        New_score=Temp;
 }
   void Display()
 {
   
     Console.WriteLine("The new value of top score is:");
     Console.WriteLine(Top_score);

     Console.WriteLine("The old value of top score was:");
     Console.WriteLine(New_score);
 }
     static void main()
{
   
     Interchange I1=new Interchange();
     I1.Swap();
     I1.Display();
     Console.ReadLine();
   }
}

No comments:

Post a Comment