Thursday 8 December 2016

Write a program that declares a structure to store the distance covered by an player along....


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. 


        #include <iostream.h>
        #include <conio.h>
        struct player
        {
             int dis;
             int min;
             int sec;
         };

        int  main()
        {
            player p1,p2;
            float t1, t2;
           
             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;

            float time1=(p1.min*60+p1.sec)/p1.dis;
            float 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;
          }
          return 0;
        }

No comments:

Post a Comment

If you have any doubt please let me know

Methods in JAVA Language

 In general, a way may be thanks to perform some task. Similarly, the tactic in Java may be a collection of instructions that performs a sel...