In: Computer Science
Mr. Rashid plans to purchase the electronics items
based on his budget. So he needs a purchase planner which will help
to calculate the price of electronics items, he can purchase based
on the available amount. If Mr. Rashid enters his budget amount and
chooses the numbers of electronic items from the list of available
electronic items, the purchase planner will calculate the cost of
electronics items based on the number of items selected, the total
cost of all the selected electronic items and also the balance
amount.
Display the list of electronic items and its price as
follows,
==============================================
1. HP Laptop --------------------200 OMR
2. Samsung Mobile S10--------225 OMR
3. Apple 10s----------------------350 OMR
#include
/* Here, we are defining a user defined structure to hold the data
related to electronic item together */
typedef struct elec_item { char *name; int cost; }EItem;
int main() {
EItem items[3]; int budget,ch; // defining the
items
//Here, you can take the inputs and define the items in a for
loop
items[0].name = "HP Laptop"; items[0].cost = 200;
items[1].name = "Samsumg Mobile S10"; items[1].cost = 225;
items[2].name = "Apple 10s"; items[2].cost = 350;
printf ("Enter Budget Amount: "); scanf ("%d", &budget);
//reading the budget from user
/* displaying the menu */
printf
("==============================================================\n");
printf ("1. %s --------------------- %d\n", items[0].name,
items[0].cost);
printf ("2. %s --------------------- %d\n", items[1].name,
items[1].cost);
printf ("3. %s --------------------- %d\n", items[2].name,
items[2].cost);
printf
("==============================================================\n");
printf ("Enter choice:"); // scanning the choice of user
scanf ("%d", &ch);
// verifying the user choice and printing a message if wrong
choice
if (ch < 3 && ch > 0) { int quantity,
total_cost;
// By taking other user inputs and caluculating the cost
printf ("How many %s: ", items[ch-1].name);
scanf ("%d", &quantity);
if ((total_cost = quantity * (items[ch-1].cost)) <= budget)
{
printf ("\tCost of 1 %s is %d\n",
items[ch-1].name, items[ch-1].cost);
printf ("\tTotal Cost = %d\n",
total_cost);
printf ("\tBalence Amount = %d\n", budget -
total_cost); }
else {
printf ("\tThis will exceed your
budget limit\n");
}
}
else {
printf ("\tThat's a wrong choice\n");
}
return 0;
}