Hi, I'm working on a program that is supposed to use a for loop to generate a number that runs in an increment to display numbers like 1,2,4,8,16,32,64...basically to double the number starting from 1.
Here is how my output should look:
1
2
4
8
16
32
64
128
and so on.
So far all I get when I run the program is either
1
Press any key to continue...
or it shows a one, but sits there for several seconds and does nothing then says "Press any key to continue".
/*
The increment expression in a for loop need not always alter the loop
control variable by a fixed amount. Instead, the loop control variable
can change in any arbitrary way. Using this concept, write a program
that uses a for loop to generate and display the progression
1, 2, 4, 8, 16, 32, and so on.
*/
#include <iostream>
usingnamespace std;
int main()
{
int i = 1;
cout << i << " " << endl;
for(i > 0; i*2; i++)
return 0;
}
While your at it, make sure your number is larger than 0 which will do nothing when doubled and smaller than (half the max size , less i), else you run into some other issues.
put your cout after the for statement
remove << " " unless writing to a file, it has no purpose on screen if you use endl.