Jul 10, 2018 at 3:17pm UTC
I cant get the discount and total right, I need the output to be like
Example 1
Enter quantity: 160
Sub Total = 544.00
Discount = 0
Total = 544.00
Example 2
Enter quantity: 380
Sub Total = 1292.00
Discount = 129.00
Total = 1162
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
void main()
{
// Veriable declaration
int qty, discount;
float price, pricelow, total;
// Input
printf("Enter Quantity: " );
scanf("%d" , &qty);
// Process
pricelow = qty * 3.40;
price = qty * 4.00;
discount = qty % 10;
if (qty > 100)
{
printf("Sub Total = %.2lf\n" , pricelow);
printf("Discount = %f\n" , discount);
printf("Total = %.2lf" , total);
}
else
{
printf("Sub Total = %.2lf\n" , price);
printf("Discount = %f\n" , discount);
printf("Total = %.2lf" , total);
}
// Output
printf("\n" );
system("pause" );
}
Last edited on Jul 10, 2018 at 3:20pm UTC
Jul 10, 2018 at 3:37pm UTC
discount = qty % 10;
Well that looks wrong. Surely it should be
discount = price - pricelow;
Last edited on Jul 10, 2018 at 3:38pm UTC
Jul 10, 2018 at 4:00pm UTC
% is NOT percentage. It is remainder from integer division. % 10 can only be 0-9 in value for any given number....
you want
discount = .1 * subtotal; //10% of the subtotal. Did you want this as an integer truncate as in your example or the actual value?
you can also say
discount = subtotal / 10; //integer division ?? did you confuse / and % ?
Last edited on Jul 10, 2018 at 4:04pm UTC
Jul 10, 2018 at 5:01pm UTC
from what I can see, float total is not given any value.
Jul 10, 2018 at 5:13pm UTC
lol sorry I did confuse / and %
Jul 10, 2018 at 5:26pm UTC
I want an actual value.
Example 1
Enter quantity: 160
Sub Total = 544.00
Discount = 0
Total = 544.00
Example 2
Enter quantity: 380
Sub Total = 1292.00
Discount = 129.00
Total = 1162
Jul 10, 2018 at 5:36pm UTC
I believe the term for price before taxes, etc. is "net". You want a discount if the net price is >= 1000, so your conditional at line 19 is also wrong.
C++ example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float val = 3.40f;
float discount_threshold = 1000.0f;
int qty = 380;
float tax = 1.05f;
float net = qty * val;
float discount = net>=discount_threshold ? net*0.10 : 0.0f;
cout << fixed << setprecision(2);
cout << "Quantity: " << qty << " @ $" << val << endl <<
"Net: $" << net << endl <<
"Discount: $" << discount << endl <<
"Pre-tax: $" << (net-discount) << endl <<
"Final: $" << (net-discount)*tax << endl << endl;
return 0;
}
Quantity: 380 @ $3.40
Net: $1292.00
Discount: $129.20
Pre-tax: $1162.80
Final: $1220.94
Edit: fixed qty/net typo in the discount
Last edited on Jul 10, 2018 at 5:57pm UTC
Jul 10, 2018 at 5:41pm UTC
I am trying to understand your logic, but why in example 1 is discount = 0?
In example 2 discount is equal to 10%.
In your code you have, if qty>100 but in your examples both are greater than 100.