In: Computer Science
Write a C program of car sale:
The Visual Studio project itself must make its output to the Console (i.e. the Command Prompt using printf) and it must exhibit the following features as a minimum:
SOLUTION:-
#include <stdio.h>
void main()
{
struct date
{
int day;
int month;
int year;
};
struct details
{
char name[20];
int price;
int code;
int qty;
struct date mfg;
};
struct details item[50];
int n, i, x, total=0;
printf("1 for Sale Car ,2 for View Sales:");
scanf("%d",&x);
switch(x)
{
case 1:
printf("Enter number of items:");
scanf("%d", &n);
fflush(stdin);
for (i = 0; i < n; i++)
{
fflush(stdin);
printf("Item name: \n");
scanf("%s", item[i].name);
fflush(stdin);
printf("Item code: \n");
scanf("%d", &item[i].code);
fflush(stdin);
printf("Quantity: \n");
scanf("%d", &item[i].qty);
fflush(stdin);
printf("price: \n");
scanf("%d", &item[i].price);
fflush(stdin);
printf("Manufacturing date(dd-mm-yyyy): \n");
scanf("%d-%d-%d", &item[i].mfg.day,
&item[i].mfg.month, &item[i].mfg.year);
}
printf(" ***** INVENTORY ***** \n");
printf("---------------------------------------------------------
---------\n");
printf("S.N.| NAME | CODE | QUANTITY | PRICE
| MFG.DATE \n");
printf("---------------------------------------------------------
---------\n");
for (i = 0; i < n; i++)
printf("%d %-15s %-d %-5d %-5d
%d/%d/%d \n", i + 1, item[i].name, item[i].code, item[i].qty,
item[i].price, item[i].mfg.day, item[i].mfg.month,
item[i].mfg.year);
printf("---------------------------------------------------------
---------\n");
case 2:
printf(" ***** INVENTORY ***** \n"); printf("--------------------------------------------------------- ---------\n"); printf("S.N.| NAME | CODE | QUANTITY | PRICE | MFG.DATE \n"); printf("--------------------------------------------------------- ---------\n"); for (i = 0; i < n; i++) printf("%d %-15s %-d %-5d %-5d %d/%d/%d \n", i + 1, item[i].name, item[i].code, item[i].qty, item[i].price, item[i].mfg.day, item[i].mfg.month, item[i].mfg.year); printf("--------------------------------------------------------- ---------\n");
for(i=0;i<n,i++){
total+=item[i].price;
}
printf("Total sales =%d",total);
}
return 0;
}