An Arithmetic Problem

Limits: 1s, 512 MB

A sequence is an arithmetic sequence if every two successive number has same difference. Suppose this is a sequence of numbers:


This is a companion discussion topic for the original entry at https://toph.co/p/an-arithmetic-problem

My code gives correct output but when i submitted it shows wrong answer. Where is the problem?

n = int(input())
for i in range(n):
x, y, z, n = map(int, input().split())
if z - y == y - x:
cal = z - y
number = cal * n
print(“Case %d: %d” % (i+1, number))
else:
print(“Case %d: Error” % (i+1))

for input 6 7 8 2 output should be 7 not 2

@hjr265

#include <iostream>

using namespace std;

int main() {
    int n , a , b , c , d;
    cin >> n ;
    
    for(int i = 1 ; i <= n ; i++){
        cin >> a >> b >> c >> d ;
        int x , y ;
        x = b-a;
        y = c-b;
        cout <<"Case"<<" "<<i<<':'<<" ";

        if(x==y)
        cout << x*d<<endl;
        else 
        cout << "Error"<<endl;
    }
}

what’s wrong in this code;
every time my answer is being accepted in the first test case … But on the 2nd test case , it is showing wrong answer,