Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #define index 4
- void clrscr(){
- system("@cls||clear");
- }
- int i;
- typedef struct {
- int no;
- char code[6];
- int stock;
- int price;
- char name[30];
- }shop;
- shop arrS[index] = {
- {01, "CR013", 5, 33000, "Bugatti Veyron"},
- {02, "CR107", 3, 41000, "Lexus LFA"},
- {03, "CR354", 1, 89000, "Audi R8"},
- {04, "CR731", 3, 62000, "BMW i8"}
- };
- void header() {
- printf("| Welcome to\n");
- printf("| Prestige Motorcars Cashier\n");
- printf("| \n\n");
- }
- void lists() {
- printf("| NO | CODE |\t\t NAME | STOCK | PRICE\t |\n");
- for (i=0; i<index; i++) {
- printf("| %d | %5s | %15s | %5d | Rp %d |\n", arrS[i].no, arrS[i].code, arrS[i].name, arrS[i].stock, arrS[i].price);
- }
- }
- void menu() {
- printf("| Our product price lists\n\n");
- lists();
- printf("\n| Menus\n\n");
- printf(" 1. Sell\n 2. Add Stock\n 3. Exit");
- }
- int main() {
- int choice, pil, sellqt, no, stock, price;
- char sellcode[6], code[6], name[30];
- header();
- home:
- menu();
- printf("\n\n| Select menu choice : ");
- scanf("%d", &choice);
- switch(choice) {
- case 1: {
- clrscr();
- do{
- printf("| You just chose 1!\n\n");
- lists();
- printf("\n\nPlease input the code [5 digit] : "); scanf("%s", &sellcode);
- for(i=0; i<index; i++) {
- if(strcmp(sellcode,arrS[i].code)==0) {
- printf("\n| Product found ! Name = %s",arrS[i].name);
- do{
- printf("\n| Please input quantity to sell [0..%d] : ", arrS[i].stock);scanf("%d", &sellqt);
- if(sellqt < arrS[i].stock) {
- arrS[i].stock = arrS[i].stock - sellqt;
- printf("\nTotal price is : Rp %d x %d = Rp %d", arrS[i].price, sellqt, arrS[i].price*sellqt);
- printf("\nThank you for selling.");
- getch();
- clrscr();
- goto home;
- }
- else {
- printf("| Quantity is not enough! \n");
- getch();
- choice = 5;
- }
- }while(choice == 5);
- }
- else if(index == 4 && strcmp(sellcode,arrS[i].code)!=0){
- choice = 4;
- }
- }
- }while(choice == 4);
- }
- case 2: {
- clrscr();
- do{
- printf("| You just chose 2!\n\n");
- lists();
- printf("\n\nPlease input the code [5 digit] : "); scanf("%s", &sellcode);
- for(i=0; i<index; i++){
- if(strcmp(sellcode,arrS[i].code)==0){
- printf("\nProduct found ! Name = %s", arrS[i].name);
- printf("\nInput quantity [0...%d] : ", arrS[i].stock);scanf("%d", &sellqt);
- arrS[i].stock = arrS[i].stock + sellqt;
- printf("\nStock successfully added.");
- getch();
- clrscr();
- goto home;
- }
- else if(index == 4 && strcmpi(sellcode,arrS[i].code)!=0){
- choice = 4;
- }
- }
- }while(choice == 4);
- }
- case 3: {
- clrscr();
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment