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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#include <cstdlib>
#include <iostream>
#include <math.h>
using namespace std;
//Prototypes
void menu();
void cls();
void getinput();
void calculation(int, double [], double [], char *[30], double []);
void output(int , char *[30], double [], double []);
//main
int main()
{
cout << "Welcome to The Batting Program." << '\n';
cout << "Please choose from below: " << '\n';
menu();
}
void menu()
{
int choice;
cout << "1. Enter the information" << '\n';
cout << "2. Exit Batting Program" << '\n';
cout << "Enter the choice you would like below: ";
cin >> choice;
switch (choice)
{
case 1:
getinput();
break;
case 2:
return;
break;
default:
cout << '\n' << "Please choose from the available" << '\n';
menu();
break;
}
}
void getinput()
{
int players;
cout << "How many Players are on the Team? ";
cin >> players;
cout <<endl;
char* *playername = new char *[30];
double* jersey = new double[players];
double* bats = new double[players];
double* hits = new double[players];
for (int counter = 0; counter < players; ++counter)
{
cout << "What is the name of player " << counter + 1 << "? ";
playername[counter] = new char[30];
cin>> playername [counter];
//cin.ignore(1000, '\n');
cout << "What is " << playername[counter] << "'s jersey number? ";
cin >> jersey [counter];
cout << "How many times has " << playername[counter] <<" been at bat? ";
cin >> bats [counter];
cout << "How many times has " << playername[counter] << " hit the ball? ";
cin >> hits[counter];
cout << '\n';
}
calculation(players, bats, hits, playername, jersey);
}
void calculation(int players, double *bats, double *hits,
char *playername[30], double* jersey)
{
int counter;
double* average = new double[players];
for (counter = 0; counter < players; ++counter)
((average [counter]) = ((hits[counter])/(bats[counter])));
cls();
output(players, playername, jersey, average);
}
void cls()
{
system("clear");
}
void output(int players, char *playername[30], double *jersey, double* average)
{
int counter;
char junk [30];
cout << "Here is the information about the players:\n";
for (counter = 0; counter < (players); counter ++)
{
cout << "Name: " << playername[counter] <<endl;
cout << "Jersey Number: " << jersey[counter] <<endl;
cout << "Batting Average: " << average[counter] * 100 <<"%" <<endl<<endl;
}
cout << "Press any key to continue...";
cin >> junk;
//cls();
menu();
}
|