I've never used a for loop before but im trying to use a for loop now instead of a while loop to print the numbers from n1 to n2 but when i set n1 to 5 and n2 to 10 it outputs 11 not al the numbers in between....
cout<<" Enter a number to start the count at. \n";
cin>>n1;
cout<<"Now enter a number to stop the count at. \n";
cin>>n2;
Let's rephrase that to a question: according to you, how is the compiler supposed to know that cout<<i<<" "; is supposed to be part of the for loop instead of a statement that is executed after the for loop?
If we use your code as an example this should be the syntax
1 2 3 4 5 6 7 8 9
cout<<" Enter a number to start the count at. \n";
cin>>n1;
cout<<"Now enter a number to stop the count at. \n";
cin>>n2;
for(int i=n1; i<=n2, i++)
{
cout << i << " ";
}
Never put a semi colon after the closing curly brace or the initialising condition parentheses.