Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Someone run through this and explain why C++(Reset explained in the body of the question)

0 votes
asked Apr 11, 2018 by SavageMango (310 points)
A Im getting random crazy numbers for a simple solution

B Im getting more than two bowls per frame

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>

using namespace std;
    

int bowl()
{
 srand(time(NULL));
 int FirstBowlarr[20];
 int SecondBowlarr[20];
 int Total = 0;
 for(int x=0;x<9;x++)
 {
   cout<<"Frame"<<x+1<<endl;
   int arr[49]={0,0,0,0,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,4,5,5,5,6,6,6,6,6,7,7,7,7,7,8,8,8,9,9,9,10,10,10};
   int RandIndex = rand() % 49 ;
    if (9 >= arr[RandIndex] >= 1 and arr[RandIndex] != 0)
    {
     cout<<"You knocked down "<< arr[RandIndex]<< " pins!"<<endl;
     int RandNumber = rand() % 49 ;
        if (arr[RandNumber]+arr[RandIndex] >= 10)
        {
            cout<<"Spare!"<<endl;
            cout<<"/"<<endl;
            arr[RandIndex]= FirstBowlarr[x];
            arr[RandNumber]= SecondBowlarr[x];
            Total += 10 + FirstBowlarr[x+1];
            int r = 10 + FirstBowlarr[x+1] ;
            cout<<r<<endl;
        }
        else
            if (9>=arr[RandNumber]>=1 and arr[RandNumber] != 0)
            {
                cout<<"You knocked down "<< arr[RandNumber]<< " pins!"<<endl;
                arr[RandIndex]= FirstBowlarr[x];
                arr[RandNumber]= SecondBowlarr[x];
                Total += FirstBowlarr[x] + SecondBowlarr[x];
                int r = FirstBowlarr[x] + SecondBowlarr[x];
                cout<<r<<endl;
            }
            
            else
            {
                cout<<"You threw a gutterball:("<< endl;
                arr[RandIndex] = FirstBowlarr[x];
                arr[RandNumber] = SecondBowlarr[x];
                Total += FirstBowlarr[x] + SecondBowlarr[x];
                int r = FirstBowlarr[x] + SecondBowlarr[x];
                cout<<r<<endl;
            }
             
    }
   
    if (arr[RandIndex]== 10)
    {
      cout<<"Strike!"<<endl;
      cout<<"X"<<endl;
    }
    
    if (arr[RandIndex]== 0)
    {
     cout<<"You threw a gutterball :("<<endl;
     int RandNumber = rand() % 49 ;
        if (arr[RandNumber] + arr[RandIndex] >= 10)
        {
            cout<<"Spare!"<<endl;
            arr[RandIndex] = FirstBowlarr[x];
            arr[RandNumber] = SecondBowlarr[x];
            Total += 10 + FirstBowlarr[x+1];
            int r = 10 + FirstBowlarr[x+1];
            cout<<r<<endl;
        }
        else
            if (9>=arr[RandNumber]>=1 and arr[RandNumber] != 0)
            {
                cout<<"You knocked down "<< arr[RandNumber]<< " pins!"<<endl;
                arr[RandIndex]= FirstBowlarr[x];
                arr[RandNumber]= SecondBowlarr[x];
                Total += FirstBowlarr[x] + SecondBowlarr[x];
                int r = FirstBowlarr[x] + SecondBowlarr[x];
                cout<<r<<endl;
            }
            
            else
            {
                cout<<"You threw a gutterball:("<<endl;
                arr[RandIndex] = FirstBowlarr[x];
                arr[RandNumber] = SecondBowlarr[x];
                Total += FirstBowlarr[x] + SecondBowlarr[x];
                int r = FirstBowlarr[x] + SecondBowlarr[x];
                cout<<r<<endl;
            }
       
    }
 }

}

int main()

{
      bowl();

}

Please log in or register to answer this question.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...