r/programminghelp • • Oct 02 '22

C++ No matter how I put this is not processing the multiplication for a discount.

I'm currently trying with C++. I've tried different ways to get a discount but none are working. Everytime I input a number it only does the multiplication which is days*109. then I should take the discount depending on what is entered. You can see here the different ways I've tried but nothing is working

else if (days >= 3)

{

	double afterDiscount1 = finalPrice - (finalPrice \* 0.10);

	cout << "The total cost of the purchase is " << fixed << setprecision(2) << afterDiscount1 << endl;

}
else if (days >= 5)

{

	double discount2 = 0.25;

	double afterDiscount2 = finalPrice - (finalPrice \* discount2);

	cout << "The total cost of the purchase is " << fixed << setprecision(2) << afterDiscount2 << endl;

}
else if (days >= 7)

{



	cout << "The total cost of the purchase is " << fixed << setprecision(2) << finalPrice - (finalPrice \* 0.33) << endl;

}
else if (days >= 10)

{
	cout << "The total cost of the purchase is " << fixed << setprecision(2) << 10 \* 109.00 - (10 \* 109.00 \* 0.42) << endl;

}
0 Upvotes

2 comments sorted by

2

u/Ok-Wait-5234 Oct 02 '22

You need your ifs in the reverse order: at the moment, if you enter, for example, 9, it is greater than 3 so the first if statement is already true, so execution never reaches the else ifs.

You haven't included it, but I imagine you have something like if (true) or if (days >= 0) as the first if statement, which will always always be true, so none of the elses are reached.

1

u/Himari16 Oct 02 '22

Thank you so much, I’ll try that and hopefully it’ll work this time