Test user input value with if statement and logical operators - C Statement

C examples for Statement:if

Description

Test user input value with if statement and logical operators

Demo Code

#include <stdio.h>
#include <stdbool.h>

int main(void){

  int age = 0;             // Age of the applicant
  int college = 0;         // Code for college attended
  int subject = 0;         // Code for subject studied
  bool interview = false;  // true for accept, false for reject


  printf("\nWhat college? 1 or 2 or 3 ");
  scanf("%d",&college);

  printf("\nWhat subject? 1 for Chemistry, 2 for economics, 3 for other: ");
  scanf("%d", &subject);

  printf("\nHow old is the applicant? ");
  scanf("%d",&age);

  if((age > 25 && subject == 1) && (college == 3 || college == 1))
    interview = true;
  if(college == 2 && subject == 1)
    interview = true;

  if(college == 3)
    interview = true;

  if(college == 1 && subject == 2 && !(age > 28))
    interview = true;

  if(college == 2 && (subject == 2 || subject == 3) && age > 25)
    interview = true;
    /*from  w  w w. j  av  a  2s  .c  o  m*/
  if(interview)
    printf("\n\ninterview\n");
  else
    printf("\n\nno interview\n");

  return 0;
}

Result


Related Tutorials