InterviewSolution
| 1. |
Solve : Plz help c++ Plz Plz? |
|
Answer» include then i get something e+xxxxx(x= number)the output is correct. It is in scientific notation.Yes its the correct output however if you want a long long number vs scientific notation, you could take a number like 284,000,000,000,000,000,000 and divide it to use the 284 and concatonate your 0's on the tail of the output. such as Code: [Select]int After_Division; cout<<After_Division<<",000,000,000,000,000,000\n";to get 284,000,000,000,000,000,000 You can use your existing output from ages below and include that in every cout<Quote aget=agem*30*24;Code: [Select]double someval=40E120; cout<<fixed<<someval<<endl; BC can you explain double someval=40E120; cout< I dont see any scale to this concationation of an INT and DOUBLE for each ms, ns, ps etc? Also aget=agem*30*24; ages=aget*60; agemils=aget*60*1000; agemics=agemils*1000; agens=agemics*1000; ageps=agens*1000; agefs=ageps*1000; is easier to follow if you change agemils=aget*60*1000; to agemils=ages*1000; and the calculation is partially redundant to the prior formula above it. It looks much cleaner as below even though you will end up with same output. aget=agem*30*24; ages=aget*60; agemils=ages*1000; agemics=agemils*1000; agens=agemics*1000; ageps=agens*1000; agefs=ageps*1000; Quote from: DaveLembke on August 16, 2012, 11:27:46 AM Looking at this conversion formula I think there is a typo too Code: [Select]aget=agem*30*24; ages=aget*60; agemils=aget*60*1000; if Agem starts as 12, we end up with: aget=12*30*24=8640 ages=8640*60=518400 agemils=8640*60*1000=518400000 AND; for the 'fixed' version: Code: [Select]aget=12*30*24=8640 ages=8640*60=518400 agemils=518400*1000=518400000 The results are the EXACT same. After I submitted it I realized it wasnt typo just a longer than needed formula... was editing my post then got pulled away from my lunch and came back and you beat me to the correction to my original post that I corrected. I should have eaten my lunch to increase blood sugar = better thinking, before posting that, and corrected it sooner than later...LOL Hypoglycemia is not fun Quote from: DaveLembke on August 16, 2012, 10:43:26 AM Yes its the correct output however if you want a long long number vs scientific notation, you could take a number like 284,000,000,000,000,000,000 and divide it to use the 284 and concatonate your 0's on the tail of the output. Good idea to suffix with 0'sWas looking back and noticed that you are using a goto statement. goto top; I'd wrap it all within a while loop and do away with the goto. If this is school work, which I am thinking it may be, an instructor might complain with that goto's lead to spaghetti code. Having started with GW-Basic as my first programming language with line numbers, when I referred to goto's when we were discussing loops and redirection, I was scolded with NEVER USE GOTO's its poor programming technique and spaghetti code. Maybe you haven't played with loops yet and will soon. They are lots of fun. C/C++ is one of my favorite languages and powerful. PERL is my 2nd favorite. Personally since then, I have used goto's as a quick fix at times than to nest everything within loops, but when creating programs I try to avoid them whenever possible vs making sloppy code with goto here, goto there, goto this_alternative_object, goto beginning_to_restart There's also another issue with goto: it's not usually implemented well (or at all) in other programming languages, decreasing portability. An example is TI-BASIC (Used on the TI-83/84 series of calculators), where if STATEMENTS and loops used a stack mechanism to remember the beginning of the statement until it was ended. Goto could be used to jump out of one of these structures, possibly starting another loop. Eventually, an ERR: MEMORY would come up because of how much memory was used by the stack mechanism and how many loops had piled up unended. Needless to say, that was a pretty serious problem.Quote from: TechnoGeek on August 17, 2012, 09:44:02 AM There's also another issue with goto: it's not usually implemented well (or at all) in other programming languages, decreasing portability. Its implementation in C++ can also be confusing. Especially if used within loops, in fact, although one would hope you wouldn't mix goto with loops. his111, don't feel like there's something terribly wrong with using goto in a small program like yours, it's just we try to avoid it for the reasons described and it's a PRACTICE that can quickly make programs far harder to read. I'm sure Dave identified it because you're new and it's something a new programmer should know. And I too hope you enjoy learning C++, it is a very nice language sometimes.Quote from: DaveLembke on August 16, 2012, 11:27:46 AM BC can you explaincasting from a int to a double does not result in any concatenation. Only narrowing conversions need a cast. Quote and the calculation is partially redundant to the prior formula above it.There is no redundancy. Any compiler worth using will optimize the operations at compile time anyway. Quote It looks much cleaner as below even though you will end up with same output.This is true. |
|