Hi Im working on a program at the moment and seem to be having issue with this section when trying to get section 3 i get section 2 Ive pasted code below any help or suggestions would be great. Thanks

if(gps=='Y'||gps=='y'&&childseat=='N'||childseat=='n')
    {
        if(stoi(daysamount)<=3)
        {
            extra=stoi(daysamount)*5;
        }
        else
        {
            extra=15;
        }
        cout<<setw(43)<<"Cost Of Extras :1"<<"      "<<extra<<endl<<endl;
    }
    else if(gps=='N'||gps=='n'&&childseat=='Y'||childseat=='y')
    {
        if(stoi(daysamount)<=12)
        {
            extra=stoi(daysamount)*12;
        }
        else 
        {
            extra=149;
        }
        cout<<setw(43)<<"Cost Of Extras :2"<<"      "<<extra<<endl<<endl;
    }
    else if(gps=='Y'||gps=='y'&&childseat=='Y'||childseat=='y')
    {
        if(stoi(daysamount)<=3)
        {
            extra=stoi(daysamount)*5;
        }
        else
        {
            extra=15;
        }
        if(stoi(daysamount)<=12)
        {
            extra=extra+stoi(daysamount)*12;
        }
        else 
        {
            extra=extra+149;
        }
        cout<<setw(43)<<"Cost Of Extras :3"<<"      "<<extra<<endl<<endl;
    }
    else
    {
        cout<<endl<<endl;
    }

|| has lower precedence than &&. To get the appropriate behavior (granted I'm assuming what behavior you want), you need parentheses:

(gps == 'Y' || gps == 'y') && (childseat == 'N' || childseat == 'n')

Edited 3 Years Ago by deceptikon

Thanks for that its always something small and thats been staring at me for most of the day... cheers

This question has already been answered. Start a new discussion instead.