Answer to Question #173875 in C for R SWASTHIK

Question #173875

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.


1
Expert's answer
2021-03-23T03:40:10-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS