Make an Inventory Program

FratBro23
Category:
Programming
Price: $5 USD

Question description

FINAL INVENT.cpp 

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

#include<string.h>

#include<iostream>

char item[3][10]={"Notebook", "Pencil", "Ballpen"}; //item[no. of strings][string length]

int itemQty[3]={10, 15, 25};

char password[] = "welcome1";

int display(int itemNo)

{

system("cls");

printf("\n\t=======================================\n\t");

printf("|||   ITEM NAME   |   NEW STOCKS-ON-HAND  |||\n\t");

printf("===========================================\n\t");

printf("||| %s\t  |%d         |||\n\t", item[itemNo], itemQty[itemNo]);

printf("=======================================\n\n\n\t");

system("pause");

}

int AddStock()

{

int qty, itemNo;

qty=0;

itemNo=0;

while((itemNo<1)||(itemNo>3))

{

system("cls");

printf("(1) Notebook\n(2) Pencil\n(3) Ballpen\n\nEnter item #: ");

scanf("%d", &itemNo);

if((itemNo>=1)&&(itemNo<=3))

{

while(qty<1)

{

system("cls");

printf("\n\nEnter quantity: ");

scanf("%d", &qty);

if(qty<1)

{

printf("\n\nInvalid input. Press any key to continue...");

getch();

}

else

{

itemNo--;

itemQty[itemNo]=itemQty[itemNo]+qty;

display(itemNo);

itemNo++;

}

}

}

else

{

printf("\n\nInvalid input. Press any key to continue...");

getch();

}

}

}

int RemoveStock()

{

int qty, itemNo;

qty=0;

itemNo=0;

    while((itemNo<1)||(itemNo>3))

{

system("cls");

printf("(1) Notebook\n(2) Pencil\n(3) Ballpen\n\nEnter item #: ");

scanf("%d", &itemNo);

if((itemNo>=1)&&(itemNo<=3))

{

while(qty<1)

{

system("cls");

printf("\n\nEnter quantity: ");

scanf("%d", &qty);

if(qty<1)

{

printf("\n\nInvalid input. Press any key to continue...");

getch();

}

else if((qty<itemQty[itemNo])||(qty=itemQty[itemNo]))

           {

itemNo--;

itemQty[itemNo]=itemQty[itemNo]-qty;

display(itemNo);

itemNo++;

                }

else

{

printf("The number requested is more than the item on stock. Press any key to continue...");

       getch();

}

}

}

else

{

printf("\n\nInvalid input. Press any key to continue...");

getch();

}

}

}

int DisplayInventory()

{

    int itemNo=0;

    system("cls");

printf("\n\t====================================\n\t");

    printf("|||   ITEM NAME   |   STOCKS-ON-HAND   |||\n\t");

printf("====================================\n\t");

while(itemNo<3)

{

         printf("|||    %s\t   |         %d         |||\n\t", item[itemNo], itemQty[itemNo]);

         itemNo++;

    }

    printf("====================================\n\n\n\t");

system("pause");

}

int ChangePass()

{

    char in_pass[8], con_pass[8], new_pass[8];

    int exit_prog=0;

    system("cls");

    printf("\n\t\t\t         CHANGE PASSWORD\n\n");

    printf("\n\n   Password: ");

    scanf("%s", &in_pass);

    if (!strcmp(in_pass, password))

    {

        system("cls");

        printf("\n\t\t\t         CHANGE PASSWORD\n\n");

        printf("\n\n  New Password: ");

        scanf("%s", &new_pass);

   printf("\n  Confirm Password: ");

   scanf("%s", &con_pass);

   if (!strcmp(new_pass, con_pass))

        {

             system("cls");                  

             printf("\n\t\t\t         CHANGE PASSWORD\n\n");

             strcpy(password, new_pass);

             printf("\n\n The password has been succesfully changed.");

             getch();

        }

        else

        {

             system("cls");

             printf("\n\t\t\t         CHANGE PASSWORD\n\n");

             printf("\n\n The password did not match. ");

             system("pause");

             getch();

         }

     }                  

     else

     {

         system("cls");

         printf("\n\t\t\t         CHANGE PASSWORD\n\n");                  

         printf("\n\n Invalid Input. ");

         system("pause");

     }

     return(exit_prog);

}

int login()

{

    char in_pass[256] = {0};

    char c;

    int pos=0, exit_prog, rpt_login=1;

   

    while((rpt_login<=3)&&(strcmp(password, in_pass)!=0))

{

        pos=0;

system("cls");

printf("\n\t\t\t\t     LOGIN\n\n\tUsername: Admin\n\n");

printf("\tPassword: ");

        do

        {

       c = getch();  

            if( isprint(c) ) 

            {

       in_pass[ pos ] = c;

       printf("%c", '*');

       }

       pos++;

         } while( c != 13 );

if(!strcmp(password, in_pass))

exit_prog=0;

else

rpt_login++;

}

if(rpt_login>3)

{

        system("cls");

        printf("\n\t\t\t       Inventory Program");

printf("\n\n\n Invalid password. Contact Technical Support Team at Extension 143. Thank you");

exit_prog=1;

}

return(exit_prog);

}

int exitprogram()

{

    int exit_prog;

    char choice[1];

    system("cls");

printf("Are you sure you want to exit the program?");

    scanf("%s", &choice);

    strupr(choice);

    if(!strcmp(choice, "Y"))

    {

        printf("Thank you for using the program."); 

        exit_prog=1;

    }

    else if(!strcmp(choice, "N"))

         exit_prog=0;

    else

    {

         printf("Invalid input.");

         exit_prog=0;

         getch();

    }

    return(exit_prog);

}

main()

{

int choice, exit_prog=0;

char password[10]={"welcome1"};

   

   exit_prog=login();

   

while(exit_prog==0)

{

system("cls");

printf("MAIN MENU");

printf("\n1. Add Stock");

printf("\n2. Remove Stock");

printf("\n3. Display Inventory");

printf("\n4. Change Password");

printf("\n5. Exit");

printf("\n\nEnter choice: ");

scanf("%d", &choice);

switch(choice)

{

case 1: AddStock(); break;

case 2: RemoveStock(); break;

case 3: DisplayInventory(); break;

case 4: exit_prog=ChangePass(); break;

case 5: exit_prog=exitprogram(); break;

}

}

getch();

}



it was our final activity for this Sem..

Something wrong with remove stock function.

Tutor Answer

(Top Tutor) Daniel C.
(997)
School: Carnegie Mellon University
PREMIUM TUTOR
Studypool has helped 1,244,100 students
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1822 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors