0

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;
}
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by FREEZX
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.