#include <iostream>
using namespace std;
int main()
{
int n1, n2; // declare two variables
cout<< "Enter two numbers: ";
cin>> n1;
cin>> n2;
i = n1; // Initialize i to n1
while( i <= n2 ){ // While i is equal or less than n2
cout<< n1 << " "; // Print out i
i = i + n2; // add i to n2
}
return 0;
}
I am just wondering what is wrong with this code. It just keeps saying that the variable i is not declared.
Here is the tutorial from the book I bought, which is recommended by this website: C++ without fear. This is the exercise.
-Write a program to print all the numbers from n1 to n2, where n1 and n2 are two numbers specified by the user.