Dog Years C++ What If I Want To Let The User Enter The Dog Age And Name?

Just started learning C++, maybe it’s gonna be a stupid question but I still wanna know the reason or solution of the problem. The project does not required the user to enter anything, but it seems more fun to me if I can write one that interact with users. However, firstly, I don’t even have the chance to enter the dog age, secondly, the dog name will always be 0 and the human age keep changing!! Can anyone give me some suggestions?

#include <iostream>

int main() {
  
  int dog_name , dog_age , early_years , later_years , human_years;

  std::cout << "What's the name of your dog? \n ";

  std::cin >> dog_name ;

  std::cout << "Enter the dog age of your dog!\n ";
  
  std::cin >> dog_age;

  early_years = 21;

  later_years = ( dog_age - 2 ) * 4;

  human_years = early_years + later_years;


  std::cout << "My name is " << dog_name << "! Ruff ruff. I am " << human_years << " years old now! \n";

}

This is what will be shown (the dog_name will always be 0 but the human_years keep changing):

$ g++ dog_years.cpp
$ ./a.out
What's the name of your dog? 
 Candy
Enter the dog age of your dog!
 My name is 0! Ruff ruff. I am -146513715 years old now!

Thanks so much!!

Hello @java9100032678, welcome to the forums! Should the name of the dog be a type int?

Actually I don’t know… I found that it can run smoothly if I only ask the age of the dog instead of both but I still wanna know why this version is not working… :sob:

When I changed the name of the dog to String, I got a more expected result. I believe String should be used here since the name of the dog isn’t an integer (unless the name is something like 1).