More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf
Premature optimization is the root of all evil --Donald E. Knuth
Although you could directly use a loop, it may be simpler to just create (and immediately print) a string of asterisks with the desired length, since std::string has a suitable constructor.
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
can you please just help me out? I've never learned this material before. Im suppose to make a bar chart where store1=1000, store2= 1200, store3=1800, store4= 800, store5 =1900. and each asterisk will represent 100.
let's think here for a moment. did store1 hold the value for the store 1? if so, you effectively destroyed its value. store1 / 100 isn't right. the first test would equal false since 0 / 100 is 0. ++store1... well would count up if it ran, but when would it stop?
loop up how to use the for statement.....................
..dude i am reading my textbook and it doesnt say anything about making bar charts with the for loop. if you are not going to try to help please do not answer at all okay? believe it or not there are beginners in this world
im thinking for ( store1 = 0; store1 / 100; ++store1 ) ? this doesnt work
Yes, but that is because you used store1 as the loop counter. You should use another variable. Also, note that the truncation means that if the number is less than 100, no asterisk will be displayed. Is this intended?
EDIT:
Originally Posted by Sabensohn70
..dude i am reading my textbook and it doesnt say anything about making bar charts with the for loop. if you are not going to try to help please do not answer at all okay? believe it or not there are beginners in this world
Read Joeman's explanation of why your loop did not work. If you refuse to listen to anything other than a direct solution, you will not gain in understanding, and thus remain a beginner forever.
Last edited by laserlight; November 24th, 2009 at 12:54 AM.
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
..dude i am reading my textbook and it doesnt say anything about making bar charts with the for loop.
Programming books do not work that way, where you see a solution for all the problems. If books were written that way, a programming book would be millions of pages long. You must use your mind and apply what concepts you've learned in solving the problem.
You have a number, and you must loop n times per 100. How many times will the loop perform? The answer is n/100 (you may need to add 1 if the number is < 100). So now you loop n/100 times. Inside that loop, you print 1 star. Lo and behold, you have your output.
In your code, you took your hard-earned data, and destroyed it when you used it as a loop counter. Just create a brand new variable and use that to count the loop. All you need is a counter, it makes no sense destroying your data and using that as the counter.
if you are not going to try to help please do not answer at all okay?
You were being helped, you just didn't know it because the answer wasn't given to you. Learning to program doesn't work that way, where you are given the answer. At some point, you have to engage your mind in thinking in logical, discrete, well-defined steps. If you can't do that, then this field of study is not for you. And believe me, it has nothing to do with intelligence -- some people can think with a "programming" brain, while others can't, regardless of how intelligent they may be in other topics.
believe it or not there are beginners in this world
Yes, and many of them, probably sitting in your class now, could finish this assignment with no problems, or at the very least, understood immediately what Joeman and laserlight are talking about.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; November 24th, 2009 at 04:12 AM.
Bookmarks