programming with loops and break question.
im writing a code where im multiplying 2 and 3 with their powers, ie (2 ^ i) * ( 3 ^ j )..n if the resultant sum is greater than 32 bits then im not storin that value in my array n so i check with the next powers ie if for some i n j the ans is less than the previous 1(since a value greater than 64bits gets truncated n the remainin number left after truncatin is less than the prev num) then im breaking n startin with the next i value...also while checkin if the answer is more than 64 bits i store it in the array only if isnt more than 64 bits..
the array should hold values like 0,1,2,3,4,6,8,9,12,18 etc n my code is not printing the values of 2 powers.. this is my code: Code:
thanks for reading! 
Re: programming with loops and break question.
itreallyhelpsi
fyouusesom ebasicgram marcositsimp ossibletowor koutwtfyour eonaboutatlea stbreaklin esattheendof eachthoug htifyouca ntbearsedw ithcapitallette rsandfullsto ps. 
Re: programming with loops and break question.
ohandusefsckingcode
blockthereisagreatbighint rightwhereyoupost anewthreadthatssodam nobviousyoumustbeposi tivelytryingtoignorestuff. 
Re: programming with loops and break question.
Code:

Re: programming with loops and break question.
hey. sorry bout that.
what i want to do is to print the different results of (2^i)*(3^j) with i and j both from 0 to 32, which will be something like this: 1,2,3,4,6,9,12,16, and so on, but obviously not in the sorted order(i'll sort it later). whats happening now with my program is that its not printing the values of any of the powers of 3. so could you please help me correct that! thanks,here's the code: Code:
#include<iostream> 
Re: programming with loops and break question.
Thanks, that's much more readable.
It seems to work OK on my system. Changing the loop limits to 6 (instead of 32, and just to limit the total output for debugging purposes) I get the following output: Code:
......0 With an upper limit of 32 this is the first part of the output for me (not incl the .....0) : Code:
1 
Re: programming with loops and break question.
tcaseshanks..
but you know some of the answers are wrong, only a few though. its like this: my compiler is of 32 bits, and in my code im checking if the storage capabilty exceeds 32 bits by checking whether the answer is less than or greater than the previous answer; and im not storing the lesser ones( since they have been truncated: eg with ((2^64)10)+19=(2^64)+9=0+9=9 (since 2^64 is basically one followed by 64 zeroes where the one at the front is discarded due to the system restrictment) but after thinking about it you might realise that my method is correct if you're adding two numbers n their sum is greater than 32 bits, because if the answer is greater than 32 bits then the front part is truncated leaving the remaining bits which is stored, and on multiplying for some cases the number remaining after truncating is still greater than the previous number so its getting stored which shudn't happen. so how do i go about correcting that? or atleast could you tell me how to check overflow while multiplying two numbers in c++ coz what ive done is for addition and not for multiplication? 
Re: programming with loops and break question.
the first line shud've been thanks.

Re: programming with loops and break question.
You just need to think about it slightly differently. Obviously you can't say if x>=2^321 because that's always going to evaluate FALSE. Let's just bring the numbers down a bit so we don't get lost in all the digits; suppose x+y has to be less than 10, and we can't say "if x+y>=10" due to overflow. Let's say x is 6. What are the possible values of y, and how do you imagine that could be figured out?

Re: programming with loops and break question.
hey thanks...
so u meant go backward from the maximum possible value right? well i tried this: Code:
and it works perfectly! thanks alot! 
All times are GMT +5.5. The time now is 08:50. 