Rohit goes to the market to buy Apples. After surveying the market he has to decide the quantity of apples he is supposed to buy.
Following are the requirements, which helps Rohit to decide how many kgs he can buy.
1. Capture the price of apple.
2. If the price of Apples is 100, the buy 5 kgs of apple.
3. If the price is an less than 100 but more than 80 then buy 8kgs of Apple.
4. If the price is less than 80 buy 10kgs of Apple.
5. Now calculate the cost price [Cost = Quantity * Price]
6. Display the cost at which Rohit has bought the Apples.
#include <stdio.h>
int main() {
int price, quantity, cost;
printf("Apple price: ");
scanf("%d", & price);
if (price >= 100)
quantity = 5;
else if (price >= 80)
quantity = 8;
else
quantity = 10;
cost = quantity * price;
printf("Rohit has bought %d kg of apples at %d\n", quantity, cost);
return 0;
}
Comments
Leave a comment