printing summay linked list

musicmancanora4's Avatar
Go4Expert Member
Hey guys just like to ask a question how i could use the variable drinkType
to access either hot or cold drinks depending on what they choose in the menu selection.

To choose 1 or 2 the same function will run but i need it to just execute
a certain part if they where to choose hot for example. If they choose cold i would need to run only the statements that print the cold and not the hot.

Both options have to call the same function though

Iv written a do while in my main to choose either
1 Hot Drinks Summary
2 Cold Drinks Summary

if they press 1 or 2 it suppose to run the function below and print out



Code:
/**************************************************  **************************
* Menu option #1: Display Summary
* Allows the user to display a summary of all hot or cold drink categories
* and items.
**************************************************  **************************/
void displaySummary(GJCType* menu, char drinkType)
{

  /*  CategoryTypePtr currentCat;
    ItemType currentItem;
    
    
    assert(menu != NULL);
    
    currentCat = menu->headCategory;
    
    while(currentCat !=NULL)
    {
        
        currentCat= currentCat->nextCategory;
    }
    print the summary of the list*/
    
   



}



Code:
#ifndef GJC_H
#define GJC_H

/* System-wide header files. */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>

/* System-wide constants. */
#define ID_LEN 5
#define MIN_NAME_LEN 1
#define MAX_NAME_LEN 25
#define MIN_DESC_LEN 1
#define MAX_DESC_LEN 250
#define NUM_PRICES 3
#define HOT 'H'
#define COLD 'C'
#define ERRORCODE 1
#define BUFFER_SIZE 800
#define NC_ARRAY_SIZE 500
#define TRUE 1
#define FALSE 0


typedef struct category* CategoryTypePtr;
typedef struct item* ItemTypePtr;

/* Structure definitions. */
typedef struct price
{
   unsigned dollars;
   unsigned cents;
} PriceType;

typedef struct item
{
   char itemID[ID_LEN + 1];
   char itemName[MAX_NAME_LEN + 1];
   PriceType prices[NUM_PRICES];
   char itemDescription[MAX_DESC_LEN];
   ItemTypePtr nextItem;
} ItemType;

typedef struct category
{
   char categoryID[ID_LEN + 1];
   char categoryName[MAX_NAME_LEN + 1];
   char drinkType;      /* (H)ot or (C)old. */
   char categoryDescription[MAX_DESC_LEN];
   CategoryTypePtr nextCategory;
   ItemTypePtr headItem;
   unsigned numItems;
} drinkType;

typedef struct gjc
{
   CategoryTypePtr headCategory;
   unsigned numCategories;
} GJCType;

int commandLineArguments(int argc, char *argv[]);
#endif
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by musicmancanora4
a certain part if they where to choose hot for example. If they choose cold i would need to run only the statements that print the cold and not the hot.
If I am getting you correctly will not a simple if block solve your problem.
Aztec's Avatar, Join Date: May 2006
Contributor
Just pass your choice 1 or 2 to the function and take decisions based on it using plain old if.

I hope it will solve your problem. If not, then please explain things more clearly so that people here can try to help you.

[edit] Didn't really read shabbir's answer. Actually he said the same thing.[/edit]

Last edited by Aztec; 19May2006 at 05:46..
musicmancanora4's Avatar
Go4Expert Member
thanks i got it