GAMENUMBERS Game of Numbers

Author : Kavya Gupta

Tester : Sidharth Sethi

Editorialist : Kavya Gupta

GAME OF NUMBERS

Bob likes to play games very much. Today, Bob is playing a game in which the number A will be given and Bob has to guess if A will be even or odd before seeing the value of A.

  • If he correctly guesses it then he wins B coins.
  • Else He will lose B coins.

Initially, he has C coins.
Since Bob thinks of even numbers as lucky numbers, He will always guess A as an even number.
You have to tell the number of coins he will have after playing this game exactly one time. Input

Format:

The first line of input will contain the number of test cases T.

  • In the next T lines, Each line will be containing 3 integers A, B, C.
  • Where A is the given value,
    • B is the winning/losing amount
    • C is the amount Bob is initially having.

Output Format:

Print the value of the number of coins Bob will have after playing the game exactly one time.

Constraints

  • 1 ≤ T ≤ 100
  • 1 ≤ A, B, C ≤ 100

Sample Input

2
1 3 5
4 4 5

Sample Output

2
9

Explanation

In the first test case, the value of A is odd so Bob loses 3 coins. Initially, he was having 5 coins, hence he has 2 coins left
In the second test case, A is even so Bob wins 4 coins, so he has now a total of 9 coins.

Solution

The approach here is to add in case of even input and subtract when it’s odd number.

#include <iostream>
using namespace std;
void techspiritss()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a % 2) cout << c - b;
    else cout << c + b;
    cout << endl;
}
int main()
{
    int t = 1;
    cin >> t;
    while (t--) techspiritss();
    return 0;
}