Hey guys,

I've got an issue with the bowling program I've created. It's outputting the wrong scores, but I believe it's because of wrong bowling code. Is there anything wrong that you can see?

One of the issues I'm having is frame 2, where the scores were 9 and 1, and it's being counted as a STRIKE, inflating the score quite a bit.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
    //declare variables
    int frame[10] = {0};
    int balls[21] = {0};
    int input_counter = 0;
    int sum = 0;
    int strike = 10;
    
    //input stream
    ifstream score;
    
    //open file and have a statement if file is not opened
    score.open("MGlane9.txt");
    if(score.fail())
    {
                    cout << "File inaccessible.";
    }
    
    //while END OF FILE is not reached
    while(!score.eof())
    
    {               
        score >> balls[input_counter];
        input_counter++;              
    }
    
    //close Input file
    score.close();
    
    for(int i=0;i<input_counter;i++)
    {
	 	//for anything other than strike
        if(balls[i] < 10)
        {
                    cout << "First bowl is " 
						 << balls[i]
                    	 << "Second bowl is " 
						 << balls[i+1] 
						 
						 << endl;
                    sum += balls[i]+ balls[i+1];
                    if(balls[i] + balls[i+1] == 10)
                    {
                    cout << "SPARE!!!";}
                    cout << "Sum is " << sum << endl;
                    cout << endl << endl;
                    i++;
        }
        
        //for strike
        if(balls[i] = 10)
        {
                    if(balls[i] = 10)
                    {
                    cout << "Strike!" << balls[i] << endl;
                    sum += balls[i] + balls[i+1];}
                    cout << "Sum is " << sum << endl;
                    cout << endl << endl;
        }
    }
    
    //preview cout       
    getchar();   
    
    //end program                
    return 0;
}

line #57 and #59.

using = instead of == fom comparing

also couldn't get these lines

if(balls[i] = 10) //use ==
{
                    if(balls[i] = 10) //use ==
///////////////////////////

why the second condition when u already did it......

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.