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 116 117 118
|
#include <iostream> // input and output
#include <iomanip> //set percision
#include <string> // allows strings
#include <fstream> // allows use of files to read and write
using namespace std;
const int ROWS = 2;
const int COLS = 5;
void Framebuild(int[][COLS], int, int, ofstream);
int GetPlayerScore(int[][COLS], int, int, int, int, int);
void printScore(int[][COLS], int);
int totalscore(int[][COLS]);
int main()
{
ofstream outputFile;
outputFile.open("bowling.txt");
int scoreboard[ROWS][COLS];
int frameScore = 0;
int shot1 = 0;
int shot2 = 0;
int frame = 1;
string playname;
cout << " BACKYARD BOWLING" << endl;
cout << " RULES: 5 frames per game" << endl;
cout << " Max Score of 50 points" << endl;
cout << " 2 Shots per frame if all 10 pins not knocked down" << endl;
cout << "Please enter Players Name: ";
cin >> playname;
cout << endl;
Framebuild(scoreboard, ROWS, frame, outputFile);
for (int y = 0; y < COLS; y++)
{
int playscore = GetPlayerScore(scoreboard, ROWS, frameScore, shot1, shot2, frame);
scoreboard[1][y] = playscore;
outputFile << scoreboard[1][y] << " ";
frame++;
}
printScore(scoreboard, ROWS);
int thescore = totalscore(scoreboard);
cout << "Thanks for playing " << playname << "! Your final score was " << thescore << " out of 50!" << endl;
system("pause");
return 0;
}
void Framebuild(int scoreboard[][COLS], int ROWS, int frame, ofstream outputFile)
{
for (int j = 0; j < COLS; j++)
{
scoreboard[0][j] = frame;
outputFile << scoreboard[0][j] << " ";
frame++;
}
}
int GetPlayerScore(int scoreboard[][COLS], int ROWS, int frameScore, int shot1, int shot2, int frame)
{
{
cout << "Enter Pins knocked down FRAME " << frame << ">";
cin >> shot1;
if (shot1 == 10)
{}
else
{
cout << "Enter Pins knocked down on second shot FRAME " << frame << ">";
cin >> shot2;
}
frameScore = shot1 + shot2;
return frameScore;
}
}
void printScore(int scoreboard[][COLS], int ROWS)
{
for (int i = 0; i < ROWS; i++)
{
for (int j = 0; j < COLS; j++)
{
cout << right << setw(3) << scoreboard[i][j] << "";
}
cout << endl;
}
}
int totalscore(int scoreboard[][COLS])
{
int totscore = 0;
for (int j = 0; j < COLS; j++)
{
totscore = totscore + scoreboard[1][j];
}
return totscore;
}
|