0

Hey guys I need some major help...I really don't know what I'm doing wrong that my computations are not coming out right........

#include <iostream> using namespace std; int main() { double order, discount,total, amount,price; cout <<"\n\tEnter order amount: "; cin >> order; if(order <=19) discount = .2; else if(order >=20 && order <=49) discount = .3; else if(order >=50 && order <=99) discount = .4; else if(order >=100) discount = .5; cout<<"\t Discount amount"<<discount<<endl; price = 99; total = order*price-discount; cout<<"\t total price "<<total<<endl; return 0; }

5th Feb 2017, 8:07 PM
Jacqueline Mcdonald
Jacqueline Mcdonald - avatar
7 Respostas
+ 1
doesn't seem to calculate the correct amount...the total I manually do on the calculator doesn't equal the output....(order amount )75*99 (price)-40% (discount)...it comes out as 7,000+...that's not right with an 40% discount
5th Feb 2017, 8:37 PM
Jacqueline Mcdonald
Jacqueline Mcdonald - avatar
0
What's the problem? the code seems correct
5th Feb 2017, 8:23 PM
Edi Lipovac
Edi Lipovac - avatar
0
Arpan, that doesn't make any difference. c++ automatically performs multiplications first so brackets are useless. maybe total = order*(price-discount);
5th Feb 2017, 8:30 PM
Edi Lipovac
Edi Lipovac - avatar
0
I didn't say It doesn't work. It's useless
5th Feb 2017, 8:34 PM
Edi Lipovac
Edi Lipovac - avatar
0
I understand. you first need to calculate the total (price * amount) then calculate the discount (total * discount) then subtract it to the total price. let's say 75 is the amount, so 75 * 99 = 7425. now we do 7425 * 0.4 = 2970 to calculate the discount . the discounted price will then be 7425 - 2970 = 4455 ;)
5th Feb 2017, 8:47 PM
Edi Lipovac
Edi Lipovac - avatar
0
Thanks for the help...it's perfect if(order <=19) discount = .2; else if(order >=20 && order <=49) discount = .3; else if(order >=50 && order <=99) discount = .4; else if(order >=100) discount = .5; cout<<"\t Discount amount"<<discount<<endl; price = 99; total =(order*price)-(order*price*discount); cout<<"\t total price "<<total<<endl; return 0; }
5th Feb 2017, 9:01 PM
Jacqueline Mcdonald
Jacqueline Mcdonald - avatar
0
no problem, good luck!
5th Feb 2017, 9:05 PM
Edi Lipovac
Edi Lipovac - avatar