Thursday, 26 May 2016

Q: Write a program that declares a structure to store the distance covered by an player along with the minutes and seconds taken to cover the distance. The program should input the records of two players and then display the record of the winner.



Program:

        #include<iostream.h>
        #include<conio.h>
        struct player
        {
            int dis;
            int min;
            int sec;
         };
       void main()
      {
        player p1,p2;
        float t1, t2;
        clrscr();
        cout<<" Enter distance covered the first player: ";
        cin>>p1.dis;
        cout<<" Enter minutes and seconds covered by the player: ";
        cin>>p1.min>>p1.sec;
        cout<<" Enter the distance covered the second player: ";
        cin>>p2.dis;
        cout<<"Enter minutes and seconds covered by the player: ";
       cin>>p2.min>>p2.sec;
       time1=(p1.min*60+p1.sec)/p1.dis;
       time2=(p2.min*60+p2.sec)/p2.dis;
      if(time1<time2)
     {
          cout<<"Player 1 distance: "<<p1.dis<<" miles in "<<p1.min<< " minutes "<<p1.sec<<"                       seconds."<<endl;
     }
    else
    {
          cout<<" Player 2 distance: "<<p2.dis<<" miles in "<<p2.min<< " minutes "<<p2.sec<<"                     seconds."<<endl;
     }
     getche();
     }



1 comment: