int i=1;
int grains=0;
cout<<"enter the grains: ";
while (cin>>grains)
{for (double a=1;a<=grains;a=a*2) i++;
cout<<"\nsquares needed: "<<i<<"\n\nenter the grains: ";
a=1;i=1}
These both do the same thing; assign one to both of the variables. I try to keep my code as compact as possible. That's probably not the best idea, but that's just how I do it.
he threw i++ to the side of the for loop, which I hate.
and
It goes out of scope at the end of the for loop.
and
I try to keep my code as compact as possible.
GUYS!!!!
thank for the help but could you please also give some reasoning after each statement??
I am new here, new to C++ too, if you don't explain to me what you mean I am right back from the start!!
Keeping the code as compact as possible. right. so, how would
a = 1; i = 1;
be more/less compact than
a = 1, i = 1;
What does "out of scope" mean?
After each loop (after it has just been executed) I want to be able to use the program again!!! (that's why the loop) so what's wrog with setting I and A back to one?
Why would you "hate"
i++
on the side of the "for loop"??
Bjarne Stroustrup suggests that.
Would you please explain to me why/if it's "bad practise" or dangerous at tmes?