problem with object-oriented
This is a bowling score calculation program.
prof. said make this much more object-oriented but i hav no idea how
so, plz help me T.T
================================================== =
Code:
#include <iostream>
using namespace std;
class game {
public:
int gamescore; //store the game score
int ball_1[12]; //1st ball
int ball_2[12]; //2nd ball
int e_ball; //bonus of 10th frame
void init();
void input();
void calc();
void showthescoreboard();
};
void game::init() {
for(int i = 0; i < 12; i++) {
ball_1[i] = 0;
ball_2[i] = 0;
}
e_ball = 0;
}
void game::input() { //enter the pins you get
cout << "Enter the number of the pins you throw down" << endl << endl;
for(int i = 1; i < 10; i++) {
cout << "FRAME " << i << endl;
cout << "1st ball: ";
cin >> ball_1[i];
if(ball_1[i] == 10) { //strike
cout << "STRIKE!!" << endl;
cout << endl;
ball_2[i] = 0;
}
else if(ball_1[i] < 10) {
cout << "2nd ball: ";
cin >> ball_2[i];
if(ball_1[i]+ball_2[i] == 10) { //spare
}
else if(ball_1[i]+ball_2[i] > 10) {
cout << "ERROR!!" << endl;
i--;
}
cout << endl;
}
else {
cout << "ERROR!!" << endl;
cout << endl;
i--;
}
}
cout << "FRAME " << 10 << endl;
while(1) {
cout << "1st ball: ";
cin >> ball_1[10];
if(ball_1[10] == 10) {
cout << "STRIKE!!" << endl;
cout << endl;
cout << "2nd ball: ";
cin >> ball_2[10];
if(ball_2[10] == 10) { //bonus
cout << "STRIKE!!" << endl;
cout << endl;
cout << "3rd ball: ";
cin >> e_ball;
if(e_ball == 10) {
cout << "STRIKE!!" << endl;
cout << endl;
break;
}
else if(e_ball < 10) {
break;
}
else {
cout << "ERROR!!" << endl;
cout << endl;
}
}
else if(ball_2[10] < 10) {
break;
}
else {
cout << "ERROR!!" << endl;
cout << endl;
}
}
else if(ball_1[10] < 10) {
cout << "2nd ball: ";
cin >> ball_2[10];
if(ball_1[10]+ball_2[10] == 10) { //bonus ball
cout << "3rd ball: ";
cin >> e_ball;
if(e_ball == 10) {
cout << "STRIKE!!" << endl;
cout << endl;
break;
}
else if(e_ball < 10) {
break;
}
else {
cout << "ERROR!!" << endl;
cout << endl;
}
}
else if(ball_1[10]+ball_2[10] < 10) {
e_ball = 0;
break;
}
else {
cout << "ERROR!!" << endl;
cout << endl;
}
}
else {
cout << "ERROR!!" << endl;
cout << endl;
}
}
}
void game::calc() { //calculator
int i = 0;
for(i = 1; i < 11; i++) {
if(i == 10) { //calculate 10th frame
gamescore += ball_1[10] + ball_2[10] + e_ball;
}
else {
if(ball_1[i] == 10) { //STRIKE
if(ball_1[i+1] == 10 && ball_1[i+2] == 10) { //turkey
gamescore += 30;
}
else if(ball_1[i+1] == 10 && ball_1[i+2] != 10) { //double
gamescore += 20 + ball_1[i+2];
}
else { //else
gamescore += 10 + ball_1[i+1] + ball_2[i+1];
}
}
else if (ball_1[i] < 10 && ball_1[i]+ball_2[i] == 10) {
gamescore += 10 + ball_1[i+1];
}
else {
gamescore += ball_1[i] + ball_2[i];
}
}
}
}
void game::showthescoreboard() {
cout << "Your total score is " << gamescore << endl;
}
int main(void) {
game play = {0};
cout << "Bowling Score" << endl << endl;
play.init();
play.input();
play.calc();
play.showthescoreboard();
return 0;
}