Hello guys, this is my second post. I have a question about While-Loop with only ONE variable.
Look at this code and run it if you want:
#include <iostream>
#include <conio.h>
using namespace std;
int main ()
{
int n;
cout << "Enter the number: ";
cin >> n;
cout << endl;
while (n>=0)
{
cout << n << " " << endl;
--n;
}
cout << endl;
cout << "Count down is done.";
getch();
}
Now, can you do the code of the output being: 1 2 3 4 5 6 7 8 9 10.
It's in ascending order.. counting up..
Is it possible to also use ONLY one variable again with incrementing using " n++ " on that WHILE loop. I tried many times but the result is always infinite loop.
#include<iostream>
int main()
{
int n;
std::cout << "Enter the number: ";
std::cin >> n;
n *= 10000;// bury the count limit in the upper digits
++n;
while( n%10000 <= n/10000 )
{
std::cout << n%10000 << " " << '\n';
n++;
}
std::cout << '\n';
return 0;
}
EDIT: Removed const int c = 10000, which would have been a 2nd variable!
Actually, would that count since it's constant and therefore not a "variable"?