165k 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.

User DavidOhara
by
7.1k points

1 Answer

4 votes

Answer:

Hi!

// First you have to initialize the variables.

int hits = 0;

int atbats = 0;

float percentaje = 0;

function eligible() {

hits = inputHits(); // Function that input the hits.

atbats = inputAtBats(); // Function that input the at bats.

percentaje = hits/atbats; // Now, you can calculate the percentaje.

if( percentaje > 0.300) { //If percentaje if greater than .300 will print Eligible for the All Stars Game.

print('Eligible for the All Stars Game.');

} else { //Otherwise will print Not elegible.

print('Not elegible.');

}

}

}

Step-by-step explanation:

User Sdfx
by
7.2k points