I am making a vertical bar graph program, and I managed to get one working, only it uses hardcoded numbers. I need it to take user input, and tried to get it to work with user input, but it goes into an infinite loop. Can someone help me out with getting it to work with user input?
Code below:
It is not an infinite loop by any means. Your nested for-loops makes it run for a realllllyyyyyyyyyyyyyyyyyyyyyyyyyyy long time.
"largest" currently stores the smallest number, and not the largest one. But say that function worked fine, and the highest number someone entered was 40.
for(int cond = 0; cond <= 5; cond++)
This will run 5 times.
for(int rows = largest; rows >= 1; rows--)
This will run 40 or so times.
for(int columns = 0; columns <= 5; columns++)
And this will run 5 times.
So the for-loop for(int cond = 0; cond <= 5; cond++) Will run all of that 5 times. which is like what, 200 rounds? Your code still needs some work.
PS. The info I just gave is not 100% correct, but its more than close enough.
Yeh. The code I gave you just puts the largest number into "largest".
I really dont know what you want your program to do, but something is definitely wrong with all these nested for-loops. If you in a good way explain what you want your program to do, I'll try and help you.
I got it working a bit more, it now prints out the entered numbers correctly but there are no # symbols.
I also got the largest actually working properly.
Can someone help me get the # symbols to print correctly?
Code:
Is being skipped. Why? Look here - for(int rows = largest; rows <= 1; rows++)
Think for a moment. What are you telling this for-loop. Say I enter 3 numbers. 4,5 and 6.
Now row = 6 because thats the largest. Then you tell the program to run the for-loop as long as 6 is less or equal to 1? Uhmm. 6 is never less or equal to 1.
Perhaps you meant - for (int rows = largest; rows <= largest; rows++) ?
Look through your code. Learn how to debug. Either look up some videos on youtube or read about it. It is very useful. Do some changes here and there and if you get any more problems feel free to post again :)