Dog Years output goes beyond million problem

Hi, currently im in the C++ dog years section course. it all went smoothly, therefore i thought i could make an improvement by adding an input and such, and it all goes well even after compiling and executing the program. as being showed below is the code i improvise:

#include <iostream>

int main() {
  int dog_age, x, y, z;
  x= early years > 2 years
  y= later years > following years
  z= human years > total human years
  x = 21;
  y = (dog_age - 2)*4;
  z = x + y;
  std::cout << "Insert your dog age";
  std::cin >> dog_age;
  std::cout << "this dog is " << dog_age << " years old, which means " << z << " years old in human years";


the problem im experiencing is when the dog to human age is being showed by a wrong answer and it goes beyond million, for example after inserting the amount of dog years which mine is 5, then the converted dog years to human years is -656219955.

i dont know is it a bug or something else, but please help and sorry for bad english

Yes it’s a bug in your code. You’re using a variable before having given it a value (which doesn’t make sense to do)


Oh i see, thanks for replying