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.
#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;
}
Comments
Leave a comment