I know I am probably just doing something dumb wrong, but I need to take a number from the user, create an infinite loop (by making my while statement true) of multiples of 2. I got the math to multiply the number from the user times itself, but I can’t get it to loop. This is the last part of my homework for the week and my brain is fried, so I can’t figure out where I went wrong!
Any help would be amazing! Here is what I have:
#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
int d;
int e;
cin >> d;
while (true)
{
e = d * d;
}
cout << e << ", ";
}
There is unreachable code at:
cout << e << ", ";Perhaps this was meant to go in the while loop?
You are assigning
ethe value ofd*dover and over. Becaused*ddoes not change, the value ofenever changes. Perhaps you should initializeeto the number you want outside of the loop, and then sete = e * 2inside of the loop, then printe. This will print multiples of your number by successive powers of 2, which is what I think you want.