batting average

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Reaper

#include <iostream>
using namespace std;

int main()
{
    int hits , bat;
    float average;

    cout << "This will display the batting average.\n\n";

    cout << "Enter how many times you were up to bat: ";
    cin >> bat;
    cout << "Enter how many hits you got: ";
    cin >> hits;

    cout.setf(ios_base::fixed , ios_base::floatfield);
    cout.precision(2);

    average = bat / hits;

    cout << "\n\n";
    cout << "The average is " << average << endl;

    return 0;
}


I had a problem with this same problem last time, but i dont remember how, i just installed ubuntu linux, so i have to recreate most of the programs i built.

this program is suppose to display the average percent, so if i said i was up to bat 10 times but only got 5 hits it should display 50.00 for 50%, but its display 2.00

any ideas would be greatly appreciated.
Change statement

average = bat / hits;

to

average = bits * 100.0 / bat;
Last edited on
Thank you vlad, i tried every other way i could think of even came close to that, but i failed to try that one, so thank you.
Topic archived. No new replies allowed.