# Find the total marks obtained according to given marking scheme

Given the answer key of N MCQ and the answer marked by the student. The task is to calculate the Marks of the student.

Marking Scheme is as follows:

- +3 marks for every correct answer.
- -1 marks for every wrong answer.
- 0 marks for not attempting the question.

**Examples:**

Input: N = 5 Answer key = {1, 2, 1, 3, 1} Student answer = {1, 3, 1, 0, 2} Output: 4 (Only 1 and 3 questions are correctly marked and 2 and 5 are marked wrong and 4 is not attempt so, (2 * 3) + (2 * -1) = 4) Input: N = 5 Answer key = {1, 2, 3, 4, 1} Student answer = {1, 2, 3, 4, 0} Output: 12 (1, 2, 3, 4 questions are correctly marked and 5 is not attempt so, (4 * 3) = 12)

**Approach:**

- Start traversing the Student_answer[].
- If the value at current index of Student_answer[] = 0 then that question is not attempted.
- Else If the value at current index is equal to the value at corresponding index in Answer_key[] then increment the count of positive answers.
- Else increment the count of negative answers.
- Print the total marks by calculating positive marks and negative marks.

Below is the implementation of the above approach:

## C++

`// C++ implementation of above approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function that calculates marks. ` `int` `markingScheme(` `int` `N, ` `int` `answerKey[], ` `int` `studentAnswer[]) ` `{ ` ` ` `int` `positive = 0, negative = 0, notattempt = 0; ` ` ` ` ` `for` `(` `int` `i = 0; i < N; i++) { ` ` ` ` ` `// for not attempt score + 0 ` ` ` `if` `(studentAnswer[i] == 0) ` ` ` `notattempt++; ` ` ` ` ` `// for each correct answer score + 3 ` ` ` `else` `if` `(answerKey[i] == studentAnswer[i]) ` ` ` `positive++; ` ` ` ` ` `// for each wrong answer score - 1 ` ` ` `else` `if` `(answerKey[i] != studentAnswer[i]) ` ` ` `negative++; ` ` ` `} ` ` ` ` ` `// calculate total marks ` ` ` `return` `(positive * 3) + (negative * -1); ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `answerKey[] = { 1, 2, 3, 4, 1 }; ` ` ` `int` `studentAnswer[] = { 1, 2, 3, 4, 0 }; ` ` ` `int` `N = ` `sizeof` `(answerKey)/` `sizeof` `(answerKey[0]); ` ` ` `cout << markingScheme(N, answerKey, studentAnswer); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of above approach ` ` ` `// Function that calculates marks. ` `class` `geeksforgeeks ` `{ ` `static` `int` `markingScheme(` `int` `N, ` `int` `answerKey[], ` `int` `studentAnswer[]) ` `{ ` ` ` `int` `positive = ` `0` `, negative = ` `0` `, notattempt = ` `0` `; ` ` ` ` ` `for` `(` `int` `i = ` `0` `; i < N; i++) { ` ` ` ` ` `// for not attempt score + 0 ` ` ` `if` `(studentAnswer[i] == ` `0` `) ` ` ` `notattempt++; ` ` ` ` ` `// for each correct answer score + 3 ` ` ` `else` `if` `(answerKey[i] == studentAnswer[i]) ` ` ` `positive++; ` ` ` ` ` `// for each wrong answer score - 1 ` ` ` `else` `if` `(answerKey[i] != studentAnswer[i]) ` ` ` `negative++; ` ` ` `} ` ` ` ` ` `// calculate total marks ` ` ` `return` `(positive * ` `3` `) + (negative * -` `1` `); ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String args[]) ` `{ ` ` ` `int` `answerKey[] = { ` `1` `, ` `2` `, ` `3` `, ` `4` `, ` `1` `}; ` ` ` `int` `studentAnswer[] = { ` `1` `, ` `2` `, ` `3` `, ` `4` `, ` `0` `}; ` ` ` `int` `N = answerKey.length; ` ` ` `int` `marking_Scheme = markingScheme(N, answerKey, studentAnswer); ` ` ` `System.out.println(marking_Scheme); ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python 3 implementation of above approach ` ` ` `# Function that calculates marks. ` `def` `markingScheme( N, answerKey, studentAnswer): ` ` ` ` ` `positive ` `=` `0` ` ` `negative ` `=` `0` ` ` `notattempt ` `=` `0` ` ` ` ` `for` `i ` `in` `range` `(` `0` `, N): ` ` ` ` ` `# for not attempt score + 0 ` ` ` `if` `(studentAnswer[i] ` `=` `=` `0` `): ` ` ` `notattempt ` `+` `=` `1` ` ` ` ` `# for each correct answer score + 3 ` ` ` `elif` `(answerKey[i] ` `=` `=` `studentAnswer[i]): ` ` ` `positive ` `+` `=` `1` ` ` ` ` `# for each wrong answer score - 1 ` ` ` `elif` `(answerKey[i] !` `=` `studentAnswer[i]): ` ` ` `negative ` `+` `=` `1` ` ` ` ` `# calculate total marks ` ` ` `return` `(positive ` `*` `3` `) ` `+` `(negative ` `*` `-` `1` `) ` ` ` ` ` `# Driver code ` `def` `main(): ` ` ` `answerKey ` `=` `[` `1` `, ` `2` `, ` `3` `, ` `4` `, ` `1` `] ` ` ` `studentAnswer ` `=` `[` `1` `, ` `2` `, ` `3` `, ` `4` `, ` `0` `] ` ` ` `N ` `=` `5` ` ` `print` `(markingScheme(N, answerKey, studentAnswer)) ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of above approach ` `// Function that calculates marks. ` `using` `System; ` ` ` `class` `GFG ` `{ ` `static` `int` `markingScheme(` `int` `N, ` `int` `[]answerKey, ` ` ` `int` `[]studentAnswer) ` `{ ` ` ` `int` `positive = 0, negative = 0, ` ` ` `notattempt = 0; ` ` ` ` ` `for` `(` `int` `i = 0; i < N; i++) ` ` ` `{ ` ` ` ` ` `// for not attempt score + 0 ` ` ` `if` `(studentAnswer[i] == 0) ` ` ` `notattempt++; ` ` ` ` ` `// for each correct answer score + 3 ` ` ` `else` `if` `(answerKey[i] == studentAnswer[i]) ` ` ` `positive++; ` ` ` ` ` `// for each wrong answer score - 1 ` ` ` `else` `if` `(answerKey[i] != studentAnswer[i]) ` ` ` `negative++; ` ` ` `} ` ` ` ` ` `// calculate total marks ` ` ` `return` `(positive * 3) + (negative * -1); ` `} ` ` ` `// Driver code ` `static` `public` `void` `Main () ` `{ ` ` ` `int` `[]answerKey = { 1, 2, 3, 4, 1 }; ` ` ` `int` `[]studentAnswer = { 1, 2, 3, 4, 0 }; ` ` ` `int` `N = answerKey.Length; ` ` ` `int` `marking_Scheme = markingScheme(N, answerKey, ` ` ` `studentAnswer); ` ` ` `Console.WriteLine(marking_Scheme); ` `} ` `} ` ` ` `// This code is contributed ` `// by Sach_Code ` |

*chevron_right*

*filter_none*

## PHP

**Output:**

12

## Recommended Posts:

- Total distinct pairs from two arrays such that second number can be obtained by inverting bits of first
- Find maximum points which can be obtained by deleting elements from array
- Find the total Number of Digits in (N!)N
- Find the total guests that are present at the party
- Jump in rank of a student after updating marks
- Program to find total number of edges in a Complete Graph
- Find out the minimum number of coins required to pay total amount
- Maximum students to pass after giving bonus to everybody and not exceeding 100 marks
- Find the total number of composite factor for a given number
- Maximum array sum that can be obtained after exactly k changes
- Total ways of choosing X men and Y women from a total of M men and W women
- Number of distinct integers obtained by lcm(X, N)/X
- Construct a frequency array of digits of the values obtained from x^1, x^2, ........, x^n
- Count of distinct sums that can be obtained by adding prime numbers from given arrays
- Total no of 1's in numbers

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.