/* Series2.c */
#include <stdio.h>

void get_choice(int *choice); /* Different from C++ */
void handle_choice(int choice);
void print_odd();
void print_even();
void print_all();

int main()
{
 int choice;  /* variable for user input */

 get_choice(&choice); /* Different from C++ */
 handle_choice(choice);

 return 0;
}

void get_choice(int *choice) /* Different from C++ */
 {
  do  /* loop until a valid choice is entered */
   {
    printf("Which series you wish to display?\n");
    printf("1 - Odd numbers from 1 to 30\n");
    printf("2 - Even numbers from 1 to 30\n");
    printf("3 - All numbers from 1 to 30\n");
    /* N.B. choice is a pointer */
    scanf("%d", choice);  /* get choice from user */
    if ((*choice < 1) || (*choice > 3))  /* if invalid entry, give message */
     {
      printf("Choice must be 1, 2, or 3\n");
     }
   } while ((*choice < 1) || (*choice > 3));
 }

void handle_choice(int choice)
 {
  switch (choice)
    {
     case 1:
       print_odd();
       break;
     case 2:
       print_even();
       break;
     case 3:
       print_all();
       break;
    }
 }

void print_odd()
 {
  int i;
  for (i = 1; i <= 30; i = i + 2)
    printf("%d ", i);
  printf("\n");
 }

void print_even()
 {
  int i;
  for (i = 2; i <= 30; i = i + 2)
    printf("%d ", i);
  printf("\n");
 }

void print_all()
 {
  int i;
  for (i = 1; i <= 30; i++)
    printf("%d ", i);
  printf("\n");
 }

