Link to home
Start Free TrialLog in
Avatar of mapper
mapper

asked on

Need Some Help...

I have some code that I can't get to compile - I just want to get the switch and functions to work properly...

Here's the code:

#include <stdio.h>
#include <stdlib.h>

/* This is the first function in the video store menu.
      it is the menus Find video(s) (by title, type, or actors) option */
      void find(void)
      {
    printf("This option not available yet.  Or words to that effect. \n");
      }

/* This is the second function in the video store menu.
      it is the Check out video(s) option */
      void check_out(void)
      {
    printf("This option not available yet.  Or words to that effect. \n");
      }

/* This is the third function in the video store menu.
      it is the Return video(s) option */
      void return_videos(void)
      {
    printf("This option not available yet.  Or words to that effect. \n");
      }

/* This is the fourth function in the video store menu.
      it is the Find all videos out to a customer option */
      void find_videos(void)
      {
    printf("This option not available yet.  Or words to that effect. \n");
      }

/* This is the fifth function in the video store menu.
      it is the Add new video(s) option */
      void add_videos(void)
      {
    printf("This option not available yet.  Or words to that effect. \n");
      }

/* This is the sixth function in the video store menu.
      it is the Print inventory list (sorted by...) option */
      void print_inventory(void)
      {
    printf("This option not available yet.  Or words to that effect. \n");
      }

int main(void)
{
      int retval;                              /* Switch Determinant */
      int menu_val;                        /* input from user for menu  
      
      printf( "SchlockLustre Video Stores -  Main Menu: \n");
      printf( "DESCRIPTION/FUNCTION:                        ENTER NUMBER: \n");
      printf( "Find video(s) (by title, type, or actors) -       1 \n");
      printf( "Check out video(s)                        -       2 \n");
      printf( "Return video(s)                           -       3 \n");
      printf( "Find all videos out to a customer         -       4 \n");
      printf( "Add new video(s)                          -       5 \n");
      printf( "Print inventory list (sorted by...)       -       6 \n");

      while ((num = scanf("%i, & menu_val)) == 1)
      {
          switch (menu_val)
        {
              case 1:
            retval = find();
            break;

              case 2:
              retval = check_out();
              break;

              case 3:
              retval = return_videos();
              break;
              
              case 4:
            retval = find_videos();
            break;

              case 5:
              retval = add_videos();
              break;

              case 6:
              retval = print_inventory();
              break;
                       
 /* not too sure about what to do here dude... */
    /*    default: */
        /* error handling goes here */
    /*    retval = ERROR_VALUE; */
    /*    break; */
    /*    }       */

 /*   return(retval);  */
   
      }                  
            
      return EXIT_SUCCESS;
      
}      


Any ideas?

Thanks,

mapper
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or, if you want to use a return value, change toht code to read

#include <stdio.h>
#include <stdlib.h>

/* This is the first function in the video store menu.
it is the menus Find video(s) (by title, type, or actors) option */
int find(void)
{
    printf("This option not available yet.  Or words to that effect. \n");
    return ( 0);
}

/* This is the second function in the video store menu.
it is the Check out video(s) option */
int check_out(void)
{
    printf("This option not available yet.  Or words to that effect. \n");
    return ( 0);
}

/* This is the third function in the video store menu.
it is the Return video(s) option */
int return_videos(void)
{
    printf("This option not available yet.  Or words to that effect. \n");
    return ( 0);
}

/* This is the fourth function in the video store menu.
it is the Find all videos out to a customer option */
int find_videos(void)
{
    printf("This option not available yet.  Or words to that effect. \n");
    return ( 0);
}

/* This is the fifth function in the video store menu.
it is the Add new video(s) option */
int add_videos(void)
{
    printf("This option not available yet.  Or words to that effect. \n");
    return ( 0);
}

/* This is the sixth function in the video store menu.
it is the Print inventory list (sorted by...) option */
int print_inventory(void)
{
    printf("This option not available yet.  Or words to that effect. \n");
    return ( 0);
}

int main(void)
{
int retval; /* Switch Determinant */
int menu_val; /* input from user for menu  

printf( "SchlockLustre Video Stores -  Main Menu: \n");
printf( "DESCRIPTION/FUNCTION:                        ENTER NUMBER: \n");
printf( "Find video(s) (by title, type, or actors) -       1 \n");
printf( "Check out video(s)                        -       2 \n");
printf( "Return video(s)                           -       3 \n");
printf( "Find all videos out to a customer         -       4 \n");
printf( "Add new video(s)                          -       5 \n");
printf( "Print inventory list (sorted by...)       -       6 \n");

while ((num = scanf("%i, & menu_val)) == 1)
{
     switch (menu_val)
        {
         case 1:
            retval = find();
            break;

        case 2:
        retval = check_out();
        break;

        case 3:
        retval = return_videos();
        break;
        
        case 4:
            retval = find_videos();
            break;

        case 5:
        retval = add_videos();
        break;

        case 6:
        retval = print_inventory();
        break;
                       
 /* not too sure about what to do here dude... */
    /*    default: */
        /* error handling goes here */
    /*    retval = ERROR_VALUE; */
    /*    break; */
    /*    } */

 /*   return(retval);  */
    
}

return EXIT_SUCCESS;

}
The compiler simply won't accept

        retval = print_inventory();

when 'print_inventory();'

is declared as

void print_inventory( void);

as an 'int' cant be assigned a 'void' value...


Feel free to ask if you neeed more information!
Avatar of mapper
mapper

ASKER

Jkr,

You left a lot for me to determine...

That's why I gave you the low mark...

Thanks though...

mapper
<shrug> - you should have asked if you needed more information...
Avatar of mapper

ASKER

Jkr -

Yeah - you're are 100% correct and I am sorry for my earlier choice of words - I have almost hammered out my problems except that the function is returning two lines form printf before it lets the user enter any information:

void add_videos(char *title, char *type, char *actor)
{
printf("Enter the title of the video?\n");
gets(title);
printf("What type is the video?\n");
gets(type);
printf("Enter upto three actors seperated by spaces:\n");
gets(actor);
}

in the main I have:

case 5:
add_videos(title, type, actor);
break;

Here is what the code looks like when it runs:

SCHLOCKLUSTER VIDEO  -  Main Menu:

DESCRIPTION/FUNCTION:                        ENTER NUMBER:
Find video(s) (by title, type, or actors) -       1
Check out video(s)                        -       2
Return video(s)                           -       3
Find all videos out to a customer         -       4
Add new video(s)                          -       5
Print inventory list (sorted by...)       -       6

5
Enter the title of the video?
What type is the video?


See what I mean?  It should give me the first line and I should be able to enter a string and then hit enter before it printf the second line...

I will float another question if you like.

Thanks,

mapper
That's indeed strange - try

void add_videos(char *title, char *type, char *actor)
{
printf("Enter the title of the video?\n");
fflush ( stdin);
gets(title);
printf("What type is the video?\n");
fflush ( stdin);
gets(type);
printf("Enter upto three actors seperated by spaces:\n");
fflush ( stdin);
gets(actor);
}
Avatar of mapper

ASKER

Jkr,

I found the fflush last night while reading and it worked! I used it in the following manner:

void add_videos(char *title, char *type, char *actor)
{
    fflush(stdin);
    printf("\nEnter the title of the video?\n");
    gets(title);
    printf("What genre is the video?\n");
    gets(type);
    printf("Enter upto three actors seperated by spaces:\n");
    gets(actor);
}

I appreciate your input though...  I am studying arrays and pointers now - I want to be able to store the data from the add_video function to an array...  I am hoping that by early next week I should be able to start morphing on it!

Thanks again,

mapper