How do I make a code display only a certain number of decimal points? For this problem, I would like it to show 3. So if a batter had 2 hits in 10 at bats, they would be batting .200
Any help is well appreciated!
#include <iostream>
using namespace std;
int main( )
{
double batting_average, at_bats, hits;
cout << "How many at bats has the player had? ";
cin >> at_bats;
cout << "How many hits has the player had? ";
cin >> hits;
batting_average = (hits / at_bats);
cout << "The players batting average is, " << batting_average << ".\n";