Answer to Question #159778 in C for sameer

Question #159778

Write a Conversion program for a Shopkeeper selling following thing. First ask the user for the quantity of fruit to buy, such as 3 apples and 2 oranges. 


1
Expert's answer
2021-01-29T17:00:34-0500
#include <stdio.h>
int main() {
    printf("Welcome what would you to buy.\n");
    printf("1. apple - 12$ per kg\n");
    printf("2. apricot - 10$ per kg\n");
    printf("3. orange - 15$ per kg\n");
    printf("4. pear - 18$ per kg\n");
    printf("5. cherry - 12$ per kg\n");
    int n;
    printf("Enter how many things do want to buy: ");
    scanf("%d", &n);
    int order[n];
    int quantity[n];
    for (int i = 0; i < n; i++) {
        printf("1 - Enter the order of your choices and 2 - Enter the quantity of your choices: \n");
        scanf("%d", &order[i]);
        scanf("%d", &quantity[i]);
    }
    int total_amount = 0;
    int orderF[5] = {1, 2, 3, 4, 5};
    int Prices[5] = {12, 10, 15, 18, 12};
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < n; j++) {
            if (orderF[i] == order[j]) {
                total_amount += Prices[i] * quantity[j];
            }
        }
    }
    printf("You must pay %d$", total_amount);
    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