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

/**************************************
 * Examples of using the scanf function
 *
 * Author: Sarah Heckman, NCSU
 * Modified by: Julio C. Bahamon, UNCC
 *************************************/
int main()
{
   char c, d;
   float f = 0.0, g = 0.0;
   int i = 0, j = 0;
   int result = 0;
   
   
   
   printf("Enter a char, a space, and a second char: ");
   
   //Expect input to be a char, a space, and a
   //second char
   result = scanf("%c %c", &c, &d);
   
   if (result != 2) {
      exit(1);
   }
   
   printf("%c %c\n", c, d);
   printf("%.2f %.2f\n", f, g);
   printf("%d %d\n", i, j);
   
   
   
   printf("\nEnter an int, a space, a double, a space, and a double: ");
   
   //Expect input to be an int, a space, a
   //double, a space, a double
   
   result = scanf("%d %f %f", &i, &f, &g);
   
   if (result != 3) {
      exit(1);
   }
   
   printf("%c %c\n", c, d);
   printf("%.2f %.2f\n", f, g);
   printf("%d %d\n", i, j);
   
   
   printf("\nEnter an int: ");
   
   //Expect input of an int
   result = scanf("%d", &j);
   if (result !=1) {
      exit(1);
   }
   
   printf("%c %c\n", c, d);
   printf("%.2f %.2f\n", f, g);
   printf("%d %d\n", i, j);
   
   
   printf("\nEnter an int, a space, a double, a space, a double, a space, and an int: ");
   
   result = scanf("%d %f %f %d", &i, &f, &g, &j);
   
   
   // Validate input count
   if (result != 4)
   {
      printf("Invalid input");
      exit(1);
   }
   
   printf("%c %c\n", c, d);
   printf("%.2f %.2f\n", f, g);
   printf("%d %d\n", i, j);
   
   return 0;
}