mardi 30 juillet 2019

Multiplying by a decimal wont give me a decimal answer to feed back into my variable

Currently using Clion to work on a homework question. I believe i am using my if-statements correctly, as-well as the double and char but it doesn't seem to be giving me the outcome i seek. The question asks: • Buy one get one half off promotion: the lower price item is half price. • If the customer is club card member, additional 10% off. • Tax is added.

I have tried to move brackets around. I have declared the .90 to a set variable and tried multiplying that but still always gives me the same answer. I think it has something to do with my if-statemets.

'

cout<<"Enter price of first item: ";
cin>>price1;
cout<<"Enter price of second item: ";
cin>>price2;

cout<<"Does customer have a club card? (Y/N): ";
cin>>clubCard;

cout<<"Enter tax rate, e.g. 5.5 for 5.5% tax: ";
cin>>taxRate;

fullSubtotal = price1 + price2;
taxRate /= 100;
taxRate += 1;

if (price1 > price2) {
    price2 /= 2.00;
    basePrice = price1 + price2;
    if (clubCard == 'y' || clubCard == 'Y') {
        cardPrice = basePrice * .90;
       finalPrice = taxRate * cardPrice;
    }
    else (clubCard == 'n' || clubCard == 'N'); {
        cardPrice = basePrice;
        finalPrice = taxRate * cardPrice;
    }
}
else {
    price1 /= 2.00;
    basePrice = price1 + price2;
    if ((clubCard == 'y') || (clubCard == 'Y')) {
        cardPrice = basePrice * .90;
        finalPrice = taxRate * cardPrice;
    }
    else ((clubCard == 'n') || (clubCard == 'N')); {
        cardPrice = basePrice;
        finalPrice = taxRate * cardPrice;
    }
}

cout<<"Base price: "<<fullSubtotal<<endl;
cout<<"Price after discounts: "<<cardPrice<<endl;
cout<<"Total price: "<<finalPrice<<endl;

return 0;

}`

Each time i enter the values for each price( 10 and 20), it gives me the correct fullSubtotal, but when i seek the corresponding cardPrice for that route (if-statement), it gives me 25. With a total price (including tax) to be 27.0625. I was expecting the output to be, cardPrice: 22.5 with finalPrice: 24.35625

Aucun commentaire:

Enregistrer un commentaire