|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
How to double int every time?
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||
|
AMD Overclocker
|
Hey guys,
__________________How would I go about doubling something EVERY instance. If I enter 1, x = 1. If I enter 2, x = 2. If I enter 3, x= 3 and so on and so forth. Trying to test something out. Thanks guys!
|
|||||||||
|
|
|
|
|
#2 (permalink) | ||||||||||||
|
Overclocker
![]()
Join Date: Oct 2006
Location: Levittown,PA / Penn State
Posts: 1,926
Rep: 86
![]() Unique Rep: 76
Trader Rating: 0
|
what do you mean?
do{ x *= 2; }while(whatever)
__________________
|
||||||||||||
|
|
|
|
|
#3 (permalink) | |||||||||||||
|
PC Gamer
|
You asked about doubling, yet you said if you enter 1 you get 1, enter 2, get 2, etc. I'm missing something, but B-80 would be correct in his x *= 2 method while performing a loop.
__________________
|
|||||||||||||
|
|
|
|
|
#4 (permalink) | |||||||||
|
AMD Overclocker
|
basically, how do I double a penny for 30 days? That type of program.
__________________First day you earn 1 cent. Second day 2 cents. Third day 4 cents. Fourth day 8 cents. Fifth day 16 cents. And so on...
|
|||||||||
|
|
|
|
|
#5 (permalink) | |||||||||||||
|
PC Gamer
|
The "x *= 2" way. I assume you know, but in case you don't *= is short hand for x = x * 2. It's just a way of saving time.
for (int i = 0; x > 30; x++) { x *= 2 } That's for Java at least.
__________________
Last edited by Nhb93 : 09-27-09 at 08:17 PM |
|||||||||||||
|
|
|
|
|
#6 (permalink) | |||||||||
|
AMD Overclocker
|
And how would I get the sum of this then?
__________________EDIT: Yes, I knew about the x *= 2. I was just commenting in regards to trying to explain myself better for ya'll. Thanks man!
|
|||||||||
|
|
|
|
|
#7 (permalink) | |||||||||||||
|
PC Gamer
|
To get the final result? Just call x for calculations, or print out x to view the number.
__________________
|
|||||||||||||
|
|
|
|
|
#8 (permalink) | ||||||||||||||
|
4.0 GHz
![]()
Join Date: Dec 2008
Location: Dripping Springs/Denton
Posts: 890
Rep: 46
![]() Unique Rep: 44
Trader Rating: 1
|
are you talking about getting the sum of all the values of x?
if so, in the loop, you would do "y+=x"
__________________
I'm a junior in college, Comp Sci major/math minor, if you wanna talk, send me a pm ![]() The *OFFICIAL* HAF 932 Case Owners Club My HAF 932 Paint Job![]() Water Cooling (own red, need black) Quote:
|
||||||||||||||
|
|
|
|
|
#9 (permalink) | |||||||||||||
|
Overclocker in Training
![]() |
Yes, but more complex than just calling x or printing it.
__________________
|
|||||||||||||
|
|
|
|
|
#10 (permalink) | ||||||||||||||
|
4.0 GHz
![]()
Join Date: Dec 2008
Location: Dripping Springs/Denton
Posts: 890
Rep: 46
![]() Unique Rep: 44
Trader Rating: 1
|
explain please
__________________
I'm a junior in college, Comp Sci major/math minor, if you wanna talk, send me a pm ![]() The *OFFICIAL* HAF 932 Case Owners Club My HAF 932 Paint Job![]() Water Cooling (own red, need black) Quote:
|
||||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|