1.11M Members

Adjustments to Inventory?

 
-1
 
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include<stdlib.h>

int fstock1, fstock2, fstock3;
int opt1, opt2, cCost, length, gTotal;
int stock1= 5;
int stock2= 10;
int stock3= 15;
//---------------------------------------------------------------------------------------------

void welcome()
{
    system ("cls");
    printf ("\n  ||||''||                               .    ...\n");
    printf ("  ||||  |||    |||''||    '||| |||.    .||    |||  .||''||.\n");
    printf ("  |||| |||'   '''   |||    |||' .||| .|||||||  .' |||  '''''\n");
    printf ("  ||||'''||     ....|||    |||         |||        '||.....\n");
    printf ("  ||||   '|||  |||  |||    |||         |||       .....  '||.\n");
    printf ("  ||||   .||  ||||  ||| :  |||         ||| :      '||   .||'\n");
    printf ("  '''''''''    '''''''''  '''''         '''        '''''''\n");
    printf ("\n\t\t\t\t\t\tCAR RENTAL COMPANY\n");
    printf ("\n\t\t\t  (Administrators ONLY)");
    printf("\n\n\n\n\n\t\t\tPress any key to proceed.");
    getch();
}



/**********************************************************************************************/
/**********************************************************************************************/
/**********************************************************************************************/
/**********************************************************************************************/



void Rents()
{
    int opt2, opt4;
    system("cls");
    printf ("\n\n\n1. First Class\n2. Second Class\n3. Third Class\n0. Exit");
    printf ("\nPlease enter the class desired to be RENTED: ");
    scanf ("%d", &opt2);
    while (opt2!= 1&& opt2!= 2&& opt2!= 3&& opt2!= 0)
    {
        printf ("Invalid option. Try again.");
        getch();
        Rents();
    }

    switch (opt2)
    {
        case 1:  if (stock1< 1)
                 {
                    printf ("We are sorry but there are no more cars of this class.");
                    printf ("\n\n1. Retry\n2. Main Menu\nPlease select an option: ");
                    scanf ("%d", &opt4);
                    while (opt4!= 1 &&opt4!= 2)
                    {
                        printf("\nInvalid option. Please try again: ");
                        opt4=NULL;
                        scanf ("%d", &opt4);
                    }
                 }
                 else
                 {
                    stock1= stock1--;
                    cCost= 2000.00;
                    printf ("\n\nThis class of car costs: $%d.\n", cCost);
                    printf ("\nHow long is the length of rent (in days)?  ");
                    scanf ("%d", &length);
                    gTotal= length*cCost;
                    printf ("\n\nThe gross total cost is $%d", gTotal);
                    printf ("\nThe remaining stock of First Class cars are: %d", stock1);
                    printf ("\n\nPress any key to proceed. ");
                    getch ();
                    system ("cls");

                }
        break;
        case 2: if (stock2< 1)
                 {
                    printf ("We are sorry but there are no more cars of this class.");
                 }
                 else
                 {
                    stock2= stock2--;
                    cCost= 1500.00;
                    printf ("\n\nThis class of car costs: $%d\n", cCost);
                    printf ("\nHow long is the length of RENT (in days)?  ");
                    scanf ("%d", &length);
                    gTotal= length*cCost;
                    printf ("\n\nThe gross total cost is $%d", gTotal);
                    printf ("\nThe remaining stock of Second Class cars are: %d", stock2);
                    printf ("\n\nPress any key to proceed.");
                    getch ();
                    system ("cls");
                 }
        break;
        case 3: if (stock3< 1)
                 {
                 printf ("We are sorry but there are no more cars of this class.");
                 }
                 else
                 {
                    stock3= stock3--;
                    cCost= 1000.00;
                    printf ("\n\nThis class of car costs: $%d\n", cCost);
                    printf ("\nHow long is the length of rent (in days)?  ");
                    scanf ("%d", &length);
                    gTotal= length*cCost;
                    printf ("\n\nThe gross total cost is $%d", gTotal);
                    printf ("\nThe remaining stock of Third Class cars are: %d", stock3);
                    printf ("\n\nPress any key to proceed.");
                    getch();
                    system ("cls");

                 }
        break;
    default: ("\nInvalid option");
    }
}


/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&& This is the Returns Function &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
********************************************************************************************
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/


void Returns()
{
    int opt5;

    system("cls");
    printf ("\n\n\n1. First Class\n2. Second Class\n3. Third Class\n0. Exit");
    printf ("\nPlease enter the class desired to be RETURNED: ");
    scanf ("%d", &opt5);
    while (opt5!=1 &&opt5!=2 &&opt5!= 3 &&opt5!= 0)
    {
    printf ("Invalid option. Please try again.");
    getch();
    Returns ();
    }

    switch (opt5)
    {
        case 0: main();
        break;
        case 1:  if (stock1>= 5)
                 {
                 printf ("The stocks for this type of car is full.");
                 printf ("\n\n\tPress any key to try again");
                 getch();
                 Returns();
                 }
                 else
                 {
                    stock1= stock1++;
                    printf ("\nThe remaining stock First Class cars are: %d", stock1);
                    printf ("\n\n\tPress any key to proceed.  (Client Records Section)");
                    getch ();
                    system ("cls");
                 }
        break;
        case 2: if (stock2>= 10)
                 {
                 printf ("The stocks for this type of car is full.");
                 printf ("\n\n\tPress any key to try again.");
                 getch();
                 Returns();
                 }
                 else
                 {
                    stock2>= stock2++;
                    printf ("\nThe remaining stock Second Class cars are: %d", stock2);
                    printf ("\n\nPress any key to proceed. (Client Records Section)");
                    getch ();
                    system ("cls");
                 }
        break;
        case 3: if (stock3>= 15)
                 {
                 printf ("The stocks for this type of car is full.");
                 printf ("\n\n\tPress any key to try again.");
                 getch();
                 Returns();
                 }
                 else
                 {
                    stock3= stock3++;
                    printf ("\nThe remaining stock Third Class cars are: %d", stock3);
                    printf ("\n\nPress any key to proceed. (Client Records Section)");
                    getch ();
                    system ("cls");
                 }
        break;
    default: ("\nInvalid option");
    getch ();
    }
}
//--------------------------------------------------------------------------------------------

void Info()
{
    FILE *Clients;
    char fname[30], sname[30], email[40], trans[6];
    int tfone;

    if((Clients=fopen("ClientInfo.txt","r"))==NULL)
    {
        printf ("The Clients Record was not found, press any button to create one.\n");
        getch();
        system("cls");
        Clients=fopen("ClientInfo.txt","a+");
    }
    else
    {
        Clients=fopen("ClientInfo.txt","a");
    }
    system ("cls");
    printf ("Enter client's First name: ");
    scanf ("%s",&fname);
    printf ("\nEnter client's Surname: ");
    scanf ("%s",&sname);
    printf ("\nEnter client's E-mail address: ");
    scanf ("%s",&email);
    printf ("\nEnter client's contact number: ");
    scanf ("%s",&tfone);
    printf ("\nDid the client RENT or RETURN a car(s)\n");
    scanf ("%s",&trans);


    fprintf (Clients,"\nTransaction done: %s",&trans);
    fprintf (Clients,"\nName of Client: %s",&fname);
    fprintf (Clients,"%s",&sname);
    fprintf (Clients,"\nE-mail Address: %s",&email);
    fprintf (Clients,"\nContact Number: %d",&tfone);
    fprintf (Clients,"\n\n\n");
    fclose (Clients);

    printf ("\nSaved!\nPress any button to proceed");
    getch();
    system("cls");
}
//----------------------------------------------------------------------------------------------

void Stock()
{
FILE *Stocks;

int stock1, stock2, stock3;

    system ("cls");
    printf ("Press any key to continue. (Stock Section)");
    getch();
    if((Stocks=fopen("Stocks.txt","r"))==NULL)
    {
        printf("The Stock Document was not found, Press any button to create one.\n");
        getch();
        system("cls");
        Stocks=fopen("Stocks.txt","a+");
    }
    else
    {
        Stocks=fopen("Stocks.txt","a");
    }
    printf ("\nThe amount of First Class cars Stocks remaining are: %d", &stock1);
    printf ("\nThe amount of Second Class cars Stocks remaining are: %d", &stock2);
    printf ("\nThe amount of Third Class cars Stocks remaining are: %d", &stock3);

    fprintf (Stocks,"\nThe amount of First Class Stocks remaining are: %d\n", &stock1);
    fprintf (Stocks,"The amount of Second Class Stocks remaining are: %d\n", &stock2);
    fprintf (Stocks,"The amount of Third Class Stocks remaining are: %d\n", &stock3);
    fclose (Stocks);

   printf("Saved!\n\nPress any button to return to menu");
   getch();
   system("cls");
   main();
}


/****************************************************************************************************************/
/****************************************************************************************************************/
/****************************************************************************************************************/



int Transactions()
{
    int opt3;

    printf ("1. Yes\t2. No");
    printf ("Are there any further transactions to be done? ");
    scanf ("%d", &opt3);
    while (opt3!= 1&& opt3!= 2)
    {
        printf ("Invalid option. Try again");
        getch ();
        Transactions();
    }
    if (opt3=1)
    {
        main();
    }
    else if (opt3=2)
    {
        printf ("\n\n\t\t\tPlease have a nice day.\n\n\t\tPress any key to exit.");
        getch();
    }
    else
    {
        printf ("That is an invalid option.");
    }
return 0;
}
//--------------------------------------------------------------------------------------------
void Final()
{
    printf ("\n\n                .|||||||||||||.\n");
    printf ("            .|||||||||||||||||||||.\n");
    printf ("         .|||||||'|||||||||||'|||||||.\n");
    printf ("       .||||||||' '|||||||||' '||||||||.\n");
    printf ("      .|||||||||   |||||||||   |||||||||.\n");
    printf ("     .||||||||||   |||||||||   ||||||||||.\n");
    printf ("    .|||||||||||   |||||||||   |||||||||||.\n");
    printf ("    .|||||||||||   |||||||||   |||||||||||.\n");
    printf ("    :|||||^|||||. .|||||||||. .||||||^||||:\n");
    printf ("    '||||| ||||||.|||||||||||.||||||| ||||'\n");
    printf ("    '||||| |||||||||||||||||||||||||| ||||'\n");
    printf ("     '|||||.                        .||||'\n");
    printf ("      '|||||.                     .|||||'\n");
    printf ("        '||||.                   .||||'\n");
    printf ("          '|||||.             .|||||'\n");
    printf ("             '||||||||||||||||||||'\n");
    printf ("                '||||||||||||||'\n");
    printf ("\n\n\t\tHave a nice day!");
}
//--------------------------------------------------------------------------------------------

int main ()
{
int opt1;

welcome();

void mainmenu()
{
    int opt1;

    system ("cls");
    printf ("1. Rent\n2. Return\n0. Exit\n\n");
    printf ("Please select the desired option:  ");
    scanf ("%d", &opt1);
    while (opt1!= 1&& opt1!= 2&& opt1!= 0)
    {
        printf ("\nThat is not an option. Try again.\n ");
        getch ();
        mainmenu();
    }
    if (opt1== 1)
    {
        Rents();
        Info();
        Stock();
        Transactions();
    }
    else if (opt1== 2)
    {
        Returns();
        Info();
        Stock();
        Transactions();
    }
    else if (opt1== 0)
    {
        Final();
        printf ("\n\n\t\tPlease have a nice day.\n\n\t\tPress any key to exit.");
        getch();
    }
}
mainmenu();
//--------------------------------------------------------------------------------------------

return 0;
}
 
0
 

(oops i erased my question)

so i did this bit of code a while back and it reaally amateur cuz im a noob
but it runs ok-ish
but my teacher wants me to put more stuff..

i understand that the text readingneeds some help
but
i dont understand how i could input more stuff..

does he mean incorporating arrays and such?

 
0
 

omg...i included the drawings....

 
0
 

does he mean incorporating arrays and such?

Why are you asking us and not your teacher?

As it stands now it's a bit of a mess...

  • You're using unportable stuff like conio and system("cls").
  • Try to replace the recursion in your input routines by iterative constructs.
  • Remove useless comments like "This is the Returns function", every C programmer will be able to figure that out when seeing void Returns().
  • Try incorporating more error handling and safety: things like scanf ("%s",&fname); aren't safe.
  • Concisely choose your variable names.
  • Avoid the use of global variables.

There's probably more, but this is what I noticed from a quick skim through your code.

 
0
 

these days im using xcode and i realized the conio.h library is absolete and just a borland thing

but unfortunately those are the required codes

i get what you mean by using those "unsafe" stuff

but what do u mean by iterative constraints?

i definitely will erase those useless comments and also change variable names
but unfortunately the use of scanf("%s"&fname) is a must, and is actually in our syllabus
I'd love to rant on the education system but i digress :)

these days my teacher goes through software development terms and processes
but nothing concerning coding rather more of a business and constructive aspect
and when i ask about my code
he just says read the syllabus
(kind of a bum teacher to be honest)

thank you sooo much for your help though
I am soooo happy to get feedback truly truly truly grateful

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: