All pastes #192783 Raw Edit

Someone

public text v1 · immutable
·published 2006-10-06 07:29 UTC
rendered paste body
#include <stdio.h>

/* et cetera */

int main(void)
{

/*  int choice declare_this MAYBE THIS ISN'T DECLARED HERE AFTER ALL */

 do {  /*  loop until 0 is selected from menu() */
    
  menu() /* call menu to get choice */
 
    switch(menuchoice)
    {
      case 5: /* quit now */
      printf("\tBye.");
      continue;

      case 1:
      add();

      case 2:
      printf("\tThis function is not yet implemented.");

      case 3:
      printf("\tThis function is not yet implemented.");

      case 4:
      printf("\tThis function is not yet implemented.");

  } while menu(choice) != 5

return 0;
}

int menu()
{
  int menuchoice;

  printf("\n\tSierra Sporting Goods\n\n");            /* Name of the company */
  printf("\t---------------------\n\n");

  printf("\t1 = Add a record\n");                     /* Menu choices begin with this line */
  printf("\t2 = Report\n");
  printf("\t3 = Delete a record\n");
  printf("\t4 = Change a record\n");
  printf("\t5 = Quit\n\n");                           /* Menu choices end with this line */
  
  scanf("%d%*c", &menuchoice); /* prompt for choice and return it to main() */
  return menuchoice;

}

add()
{
      int number;
      int type;
      int quantity;
      int count_tot = 0;	
      int quantity_tot = 0;

      double cost;
      double price;
      double cost_tot = 0;                                        /* Let's initialize the variables */
      double price_tot = 0;                                       /* whose values are not obtained */
      double profit_tot = 0;                                      /* by user input */
      double grand_cost = 0;
      double grand_price = 0;
      double grand_profit = 0;

      char continuechoice;

  do
    {

/*      printf("\n\tSierra Sporting Goods\n"); */
/*      printf("\t---------------------\n\n"); */

      printf("\tEnter the product number: ");                     /* BEGIN prompting user for input */
      scanf("%d%*c", &number);
    while (number < 1 || number > 9999)                           /* Validate 'number' variable */
        {
          printf("\tProduct number is out of range, please enter a value between 1 and 9999\n");
          printf("\tEnter the product number: ");
          scanf("%d%*c", &number);
        }

      printf("\tEnter the product type  : ");
      scanf("%d%*c", &type);
    while (type < 1 || type > 5)                                  /* Validate 'type' variable */
        {
          printf("\tProduct type is out of range, please enter a value between 1 and 5\n");
          printf("\tEnter the product type  : ");
          scanf("%d%*c", &type);
        }

      printf("\tEnter the quantity      : ");
      scanf("%d%*c", &quantity);
    while (quantity < 1 || quantity > 50)                         /* Validate 'quantity' variable */
        {
          printf("\tProduct quantity is out of range, please enter a value between 1 and 50\n");
          printf("\tEnter the quantity      : ");
          scanf("%d%*c", &quantity);
        }

      printf("\tEnter the cost          : ");
      scanf("%lf%*c", &cost);
    while (cost < 5.00 || cost > 900.00)                          /* Validate 'cost' variable */
        {
          printf("\tProduct cost is out of range, please enter a value between 5.00 and 900.00\n");
          printf("\tEnter the cost          : ");
          scanf("%lf%*c", &cost);
        }

      printf("\tEnter the price         : ");
      scanf("%lf%*c", &price);
    while (price < 6.00 || price > 1000.00)                       /* Validate 'price' variable */
        {
          printf("\tProduct price is out of range, please enter a value between 6.00 and 1000.00\n");
          printf("\tEnter the price         : ");
          scanf("%lf%*c", &price);                                /* DONE prompting user for input */
        }

      printf("\n\tThe product number is --> %04d\n", number);     /* Display 'number' in zero-filled field, width 4 */
      printf("\tThe product type is ----> %d\n", type);
      printf("\tThe quantity is --------> %d\n", quantity);
      printf("\tThe cost is ------------> %.2lf\n", cost);
      printf("\tThe price is -----------> %.2lf\n", price);

      count_tot++;                                                /* Increase order count by 1 */
      price_tot = quantity * price;                               /* CALCULATE: total order price, */
      cost_tot = quantity * cost;                                 /*            total order cost, */
      profit_tot = price_tot - cost_tot;                          /*            order profit, */
      quantity_tot = quantity_tot + quantity;                     /*            total qty of products, */
      grand_price += price_tot;                                   /*            grand price, */
      grand_cost += cost_tot;                                     /*            grand cost */
      grand_profit += profit_tot;                                 /*            and grand profit */

      printf("\n\tThe subtotal price is   : %.2lf\n", price_tot); /* Display subtotals */
      printf("\tThe subtotal cost is    : %.2lf\n", cost_tot);
      printf("\tThe subtotal profit is  : %.2lf\n", profit_tot);

      printf("\n\tAnother product? (Y/N): ");                     /* Ask user whether to continue do/while loop, */
      scanf("%c%*c", &continuechoice);                                    /* read in the user's choice as a char */
      choice = toupper(continuechoice);                                   /* and format it to uppercase */

    }
  while (continuechoice != 'N');
}

getint()
{
  receive item to prompt for and min/max range
  return appropriate int if valid
  display error msg if invalid
}

getreal()
{
  receive item to prompt for and min/max range
  return appropriate double if valid
  display error message if invalid
}

total()
{
  receive two arguments (quantity and cost OR quantity and price)
  return total
}

show()
{
  receive 4 args: product_number, quantity, cost, and price
  total() /* to get total cost */
  total() /* to get total price */

  display everything (as in lab 2)
  return nothing
}