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 <iostream>
#include <sstream>
#include <string>
using namespace std;
int WhatPars(int i, int x);
void Title ();
int GetScores(int numarray[]);
const int ARRAY_MAX = 18;
int main()
{
Title(); //call function to write title to screen
int ScoreArray [ARRAY_MAX];
GetScores(ScoreArray); // call function to collect scores into array
cout << endl;
cout <<" Press any Key then <Enter> to Finish\n";
char f ;
cin >> f ;
return 0;
}
//******************* T I T L E **************************
void Title ()
{
cout << " Golf Scores for Crowlands Heath \n";
cout << " Par 66 \n";
cout << "\n";
}
//**************** Get Scores from User *****************
int GetScores (int numarray[])
{
int x =0;
int i = 0;
int y =0;
int array[ARRAY_MAX];
for ( x = 1; x <19; x++ )
{
cout << x << ": " ;
string input =" ";
while (true) // Validate entry between 1 - 9
{
getline(cin, input);
stringstream qwerty(input);
if (qwerty >> y && y > 0 && y <10)
break;
}
array[i] = y;
WhatPars(i,y); // call function to process Pars, birdies etc
i++;
} //end for loop
//***************** Add Scores together *******************
int yourscore =0;
x = 0 ;
for ( x =0; x < ARRAY_MAX; x++ )
{
yourscore += array[x];
}
cout << "\n Your Score Today: " << yourscore <<" \n";
cout << endl;
cout << " What's your Handicap ? : ";
int hndcp =0;
string input =" ";
while (true) // Validate entry between 1 -28
{
getline(cin, input);
stringstream qwerty(input);
if (qwerty >> hndcp && hndcp > 0 && hndcp <29)
break;
}
int handicapscore = yourscore - hndcp;
int h = 66 - handicapscore;
int m = handicapscore - 66;
if (handicapscore < 66)
cout <<"\n Great Round ! You were " << h << " Under Par\n";
else if (handicapscore > 66)
cout <<"\n Oh dear ! You were " << m << " Over Par\n";
else
cout <<"\n Well done ! You were Level Par with your handicap\n";
cout << endl;
}
//**************** What are Pars, bogeys, birdies etc *****************
int WhatPars(int i, int x)
{
int y =0;
int ParArray[ARRAY_MAX] = {4,3,4,4,3,3,4,3,5,4,3,4,4,3,3,4,3,5 };
// (y) is the array number which refers to par
// (x) is the score coming in
y = ParArray[i];
if
(x == y - 3 )
cout <<" Albatross\n";
else if ( x == y - 2 )
cout << " Eagle\n";
else if ( x == y - 1 )
cout << " Birdie\n";
else if (x == y )
cout << " Par\n";
else if (x == y + 1 )
cout << " Bogey\n";
else if (x == y + 2 )
cout << " Double Bogey\n";
else if (x == y + 3 )
cout <<" CRAP\n";
else if (x == y + 4 )
cout <<" CRAP\n";
else if (x == y + 5 )
cout <<" CRAP\n";
else if (x == y + 6 )
cout <<" CRAP\n";
}
|