|declaring unknown amount of variables|
Entering and summing a user specified number of numbers is not creating a user specified number of variables.
Creating a user specified number of variables could easily be handled with a C++ container. A std::vector
would be a good choice. The size is flexible.
As others have pointed out what you actually ask is how to keep track of entering a varying number of inputs. Three variables would work. One for the number of inputs. The second to get each input from the user in a loop; lather, rinse and repeat. The third to hold the sum of all the individual inputs.
There are two basic strategies for how to get the input from the user.
1. ask the user how many integers they want to enter and loop input for that number. Rather inflexible IMO. What if the user entered an incorrect amount?
2. In a loop ask the user to enter an integer, specifying a terminating condition (-9999 is a valid and reasonable terminating number). Add the input to the summing variable, increment a count variable by one to keep track of each input.
Exactly how you write the code is something you should tackle, after all this is your assignment. We can offer help with code you've written, we won't do the assignment for you.