dimanche 3 octobre 2021

If statement executing regardless of the condition

I'm writing a C program that asks the user for a variety of inputs, one is a Yes or No question. If you put Y, or y, the If statement is supposed to execute. However, no matter what you input, it goes through with the If statement.

double phonePrice;
double phoneTax;
double phoneTotal;
double phoneApplePrice;
double phoneSubtotal;
double temp;
int yearsAppleCare;
char userAnswer;

//prompting for price
printf("Enter the price of the phone> ");
scanf("%f", &phonePrice);
fflush(stdin);

//prompting for iphone
printf("Is the phone an iPhone (Y/N) ?> ");
scanf("%c", &userAnswer);
fflush(stdin);

//nested if statements asking for apple care amount
if(userAnswer=="Y"||"y")
{
    printf("Enter the number of years of AppleCare> ");
    scanf("%d", &yearsAppleCare);
    
    if(yearsAppleCare<=0)
    {
        printf("You must choose at least 1 year of AppleCare");
        return 0;
    }
}

Any help with this would be appreciated.

Aucun commentaire:

Enregistrer un commentaire