OK so I tried to work on it a little more, can someone give me an idea as to how correct my updated code is. i am trying to run a number generator 1000 times to get statistical probabilities for the upcoming season for a particular hitter. AM I WAY OFF??
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(){
double batAvg, slugPct;
int atBats = 0,
outs = 0,
walks = 0,
hits = 0,
singles = 0,
doubles = 0,
triples = 0,
homeRuns = 0,
randomNum = 1 + rand() % 100;
//srand(time(NULL)); // random number generator
//1-100
for(atBats=0; atBats <= 1000; atBats++)
hits = (singles + doubles + triples + homeRuns);
batAvg = hits / (atBats - walks);
slugPct = ((singles + (doubles * 2) + (triples * 3) + (homeRuns * 4)) /
(atBats - walks));
if(randomNum >= 1 && randomNum <=20)
singles += 1;
else if(randomNum > 20 && randomNum <= 35)
doubles += 1;
else if(randomNum > 35 && randomNum <= 44)
triples += 1;
else if(randomNum > 44 && randomNum <= 49)
homeRuns += 1;
else if(randomNum > 49 && randomNum <=65)
walks += 1;
else
outs += 1;
cout << "The projected number of singles is " << singles << endl;
cout << "The projected number of doubles is " <<
doubles << endl;
cout << "The projected number of triples is " <<
triples << endl;
cout << "The projected number of homeruns is " << homeRuns << endl;
cout << "The projected number of walks is " << walks << endl;
cout << "The projected number of hits is " << hits << endl;
cout << "The projected batting average for next year is " << batAvg << endl;
cout << "The projected slugging percentage for next year is " << slugPct << endl;
return 0;
}// end main