Would someone mind double checking my code? There are newlines after each line displayed that I didn't code for and a lot of dead space at the end. I get the general output that I need (All even numbers between 1 and 100) but I'm concerned that these newlines and the dead space is a sign of a mistake that I've made. When I use the C++ Shell online I don't get all the dead space but the unexpected newlines are still there. Is this to be expected when one uses do...while? I'm new to C++ and I have very, very little prior experience in programming of any sort. Thanks for any help that anyone can provide.
//Print out of all even numbers between 1 and 100 using while loop.
#include "stdafx.h" // Required for Visual Studio
#include <iostream>
usingnamespace std;
int main() {
int number = 1;
int pause; // Visual Studio work around that I found
do {
cout << endl;
number++;
do {
cout << "Number: " << number << endl;
number ++;
} while (number % 2 == 0);
}
while (number <= 100);
cin >> pause; // Visual Studio work around that I found
return 0;
}
line 13: Every time you iterate through your loop, you create a new line before printing out the number.
Line 10: You don't need this if you want to pause the console.
line 23: Change to system("pause");