// mc.c - Main program of client - Written by developer, not by rpcgen

#include <stdio.h>
#include <ctype.h>
#include <rpc/rpc.h>
#include "mc.h"

mypair p;

int 
main(int argc, char *argv[])
{
  CLIENT         *cl;    /* a client handle */
  char            choice[256];
  int             v;

  if (argc != 2){
    fprintf(stderr, "Usage: %s server\n", argv[0]);
    exit(1);
  }
  if (!(cl = clnt_create(argv[1], MCPROG, MCVERS, "tcp"))) {
    /*
     * CLIENT handle couldn't be created, server not there.
     */
    clnt_pcreateerror(argv[1]);
    exit(1);
  }

  while (1) {
    puts("\n");
    puts("\t1. Add\n");
    puts("\t2. Subtract\n");
    printf("\tEnter your choice: ");
    scanf("%s", choice);
    if (choice[0] == '1') {
      printf("\nEnter the two integers to add: ");
      scanf("%d %d", &(p.arg1), &(p.arg2));
      v = (*add_1(&p,cl));
      printf("The sum is %d\n", v);
    }else if (choice[0] == '2') {
      printf("\nEnter the two integers to subtract: ");
      scanf("%d %d", &(p.arg1), &(p.arg2));
      v = (*subtract_1(&p,cl));
      printf("The difference is %d\n", v);
    } else
      break;
  }
  clnt_destroy(cl);
  printf("\nGood Bye\n");
  return 0;
}
