VIVA ON EVEN NUMBERS - CPPIOA001

Description:

A maths teacher asks her students to give 3 examples for positive even numbers. When the student specifies a correct answer, his/her score is incremented by 1. When the student specifies a positive odd number, his/her score is decremented by 0.5. When the student specifies a negative number, he/she will not be given any more chances to correct his or her mistake and his/her score will be decremented by 1. So a student's turn comes to an end when he/she has correctly specified 3 positive even numbers or when the student has specified a negative number. Few students didn't know the difference between odd numbers and even numbers and they made many mistakes and so it was difficult for the teacher to maintain the scores. The teacher asks for your help. Can you please help her by writing a program to calculate the score? Input consists of a list of integers. Output consists of a single line. The score needs to be displayed correct to 1 decimal place. Refer sample output for details. Sample Input 1: 4 6 -4 Output:1 Sample Input 2: 2 4 6 Output:3 Test Case 1 Input (stdin) 4 6 8 Expected Output 3 Test Case 2 Input (stdin) 4 5 6 Expected Output 1.5

Program :

#include<iostream>

using namespace std;

int main()

{

  int a,b,c;

  float i=0;

  cin>>a>>b>>c;

  if(a%2==0 && a>0)

    i++;

  else if(a%2!=0 && a>0)

    i=i-0.5;

  else

    i--;

  if(b%2==0 && b>0)

    i++;

  else if(b%2!=0 && b>0)

    i=i-0.5;

  else

    i--;

  if(c%2==0 && c>0)

    i++;

   else if(c%2!=0 && c>0)

    i=i-0.5;

  else

    i--;

  cout<<i;

return 0;

}