hey guys, i am working my way through C++ primer 5th ed. and in the first chapter it gives a problem to solve.
problem: write a program that prompts the user for two integers. Print each number in the range specified by those two integers.
I was really dumbfounded at first, as this was different from the examples before. So i searched online for an example to go through, and they used the "Print_Range" function.
Now at this early in the book, there is no mention of this function, so I conclude that that can't be what they are looking for.
Here is my code that i came up with, which I don't think is 'correct', but it gets the job done.
Also- I am using while loop, because that was the last topic before this question.
Code:
#include <iostream>
int main()
{
int v1 = 0, v2 = 0; //setting 2 variables for cin
std::cout << "Please enter 2 integers: " << std::endl;
std::cin >> v1 >> v2;
std::cout << "The numbers between " << v1 << " and " << v2 << " are: "
<< std::endl;
int v3 = v2 - 2; // while loop was going over v2, added v3 to compensate.
while(v1 <= v3) {
++v1;
std::cout << v1 << std::endl;
}
return 0;
}