Finding discount

#include <iostream>
using namespace std;
int main()
{
int quantity;
int price;

cout<<"Enter the quantity:";
cin>>qunatity;
cout<<"Enter the price:";
cin>>price;
double total_price=qunatity*price;
int discount=(90/100)*500;

if (total_price<500) {
cout<<"Total_price:"<<total_price;
} else {
cout<<"total_price:"<<total_price-discount;
}

}
I want to apply a discount of 10% if total price is more than 500. please help
Perhaps:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;

int main()
{
	int quantity {};
	double price {};

	cout << "Enter the quantity: ";
	cin >> quantity;

	cout << "Enter the price: ";
	cin >> price;

	const auto total_price {quantity * price};

	if (total_price <= 500)
		cout << "Total_price: " << total_price;
	else
		cout << "total_price: " << 0.9 * total_price;
}



Enter the quantity: 10
Enter the price: 60
total_price: 540

Last edited on
PLEASE learn to use code tags, they make reading and commenting on source code MUCH easier.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

Some formatting & indentation would not hurt either
int is for integers
90 is an integer literal
operations between integers result in an integer, so 90/100 is 0 and you have a 90 remainder

you may want to operate with floating point values, for that use double.
90.0 is a double literal
operations with a floating point value result in a floating point value, so 90.0 / 100.0 is quite near to 0.1
Last edited on
Topic archived. No new replies allowed.