134k views
0 votes
Write a program that takes two ints as input from the keyboard, representing the number of hits and the number of at bats for a batter. Then calculate the batter’s hitting percentage and check if the hitting percentage is above .300. If it is, output that the player is eligible for the All Stars Game; otherwise, output that the player is not eligible. Maintain floating point precision when calculating the hitting percentage

1 Answer

2 votes

Answer:

#include <iostream>

using namespace std;

int main() {

int nhits,nbats;//declaring number of hits and number of bats..

cin>>nhits>>nbats;//promting nhits and nbats..

float perc=(float(nhits)/nbats)*100;//calculating percentage..

if(perc>300)//checking eligibility.

{

cout<<"Eligible for ALL STARS GAME"<<endl;

}

else

cout<<"NOT Eligible"<<endl;

return 0;

}

Output:-

55

7

Eligible for ALL STARS GAME.

Step-by-step explanation:

I have taken two integer variables nhits and nbats for number of hits and number of bats.Prompting them from the user.After that i am calculating the percentage and it needs to be a float variable.So I have done typecasting for the that converting 1 integer to float so that the answer will come in float.After that checking the eligibility and printing the message.

User Samuel Calderon
by
5.3k points