Why am i getting a segmentation fault when i try to compile this code?

#include <iostream>
using namespace std;
int main()
{
    bool x;
    string odgovori;
    cin>>odgovori;
    int xd[2], rez=0, vkupno=0, odlen=odgovori.length();
    xd[1]=1;
    
    for(int i=0; i<odlen; i++)
    {
            if(odgovori[i]=='O')
            {
                                if((xd[1]==1)&&(x==false))
                                {
                                            rez=rez+1;
                                            x=true;
                                }
                                else{
                                xd[2]=xd[1]*2;
                                rez=rez+xd[2];
                                xd[1]=xd[2];
                                }
            }
            else if(odgovori[i]=='X')
            {
                 rez=0;
                 xd[1]=1;
            }
            else if(odgovori[i]=='B')
            {
                 vkupno=vkupno+rez;
                 xd[1]=1;
            }
    }
    cout<<vkupno;
}

That's because there are xd[0] and xd[1] only elements in the array int xd[2] ;)...

Oh yeah! xD

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.