• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 02:14
CET 08:14
KST 16:14
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12
Community News
$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)11Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns6[BSL21] Non-Korean Championship - Starts Jan 103SC2 All-Star Invitational: Jan 17-1822Weekly Cups (Dec 22-28): Classic & MaxPax win, Percival surprises3
StarCraft 2
General
Spontaneous hotkey change zerg Chinese SC2 server to reopen; live all-star event in Hangzhou Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns SC2 All-Star Invitational: Jan 17-18 Weekly Cups (Dec 22-28): Classic & MaxPax win, Percival surprises
Tourneys
$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7) WardiTV Winter Cup WardiTV Mondays SC2 AI Tournament 2026 OSC Season 13 World Championship
Strategy
Simple Questions Simple Answers
Custom Maps
Map Editor closed ?
External Content
Mutation # 508 Violent Night Mutation # 507 Well Trained Mutation # 506 Warp Zone Mutation # 505 Rise From Ashes
Brood War
General
I would like to say something about StarCraft Potential ASL qualifier breakthroughs? BGH Auto Balance -> http://bghmmr.eu/ BW General Discussion StarCraft & BroodWar Campaign Speedrun Quest
Tourneys
[Megathread] Daily Proleagues [BSL21] Grand Finals - Sunday 21:00 CET [BSL21] Non-Korean Championship - Starts Jan 10 SLON Grand Finals – Season 2
Strategy
Game Theory for Starcraft Simple Questions, Simple Answers Current Meta [G] How to get started on ladder as a new Z player
Other Games
General Games
Awesome Games Done Quick 2026! Mechabellum Beyond All Reason Stormgate/Frost Giant Megathread General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas
Community
General
All nighter for the AP Biology exam? US Politics Mega-thread European Politico-economics QA Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List TL+ Announced
Blogs
My 2025 Magic: The Gathering…
DARKING
Physical Exercise (HIIT) Bef…
TrAiDoS
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
James Bond movies ranking - pa…
Topin
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1949 users

The Big Programming Thread - Page 109

Forum Index > General Forum
Post a Reply
Prev 1 107 108 109 110 111 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
fabiano
Profile Blog Joined August 2009
Brazil4644 Posts
January 22 2012 05:07 GMT
#2161
looks like milesTraveled doesnt exist in the class scope, it only exists in the button1_Click method. Make the milesTravelled an attribute to the class you are working with.
"When the geyser died, a probe came out" - SirJolt
woozie
Profile Joined July 2010
Sweden53 Posts
Last Edited: 2012-01-22 05:54:18
January 22 2012 05:38 GMT
#2162
On January 22 2012 14:07 fabiano wrote:
looks like milesTraveled doesnt exist in the class scope, it only exists in the button1_Click method. Make the milesTravelled an attribute to the class you are working with.

How do I make it an attribute to the class I'm working with?

Edit:
I managed to make it work. Thanks for the help.
Warri
Profile Joined May 2010
Germany3208 Posts
Last Edited: 2012-01-22 23:48:52
January 22 2012 23:47 GMT
#2163
I have a problem with Threads in java.
Basically i want a loop to be run permanently and have it paused/resumed when i press a button.
I have created a new thread for the loop

public class loop extends Thread{
public void run(){
do while
}
}
and initialize it in the main(); (in another class)

public static void main(String[] args) {

Thread thread1 = new loop();
thread1.start();
}

Now, ive read that to make the thread pause i should use thread1.wait(); and thread1.notify(); but i just dont understand how to implement the keylistener in main();
freelander
Profile Blog Joined December 2004
Hungary4707 Posts
Last Edited: 2012-01-22 23:57:49
January 22 2012 23:55 GMT
#2164
Do you want to make a GUI for your program?

If you just start out learning about threads I don't recommend that, because the GUI starts its own threads. So it gets a bit complicated.

I recommend putting the sleep in your run() method in the loop class:
public void run(){
while(true){
sleep();
"Someone pressed A";
}

}
And all is illuminated.
Warri
Profile Joined May 2010
Germany3208 Posts
Last Edited: 2012-01-23 00:04:53
January 22 2012 23:57 GMT
#2165
Nah, no GUI involved. I just need that loop to be interrupted whenever a button is pressed, thus i made it in an extra thread.

^that would mean it would only pause once every cycle of the loop, which can be quite long. I need it to pause immediately when i push the button.
Kentor *
Profile Blog Joined December 2007
United States5784 Posts
January 23 2012 07:11 GMT
#2166
On January 20 2012 12:59 D4Lorg wrote:
hey, today at work ive been thinking, what are each languages respective "bibles".
C is obviously the K&R and
C++ is arguably C++ programming language by stroustrup.
anyone know any others?
maybe "the rails 3 way" for rails and "programming perl" (o'reilly) for perl?

Ruby is The Ruby Programming Language by Matz
divito
Profile Blog Joined January 2011
Canada1213 Posts
Last Edited: 2012-01-24 23:01:21
January 23 2012 07:34 GMT
#2167
Just thought I'd add something to the mix: I've purchased and collected eBooks for years now, and have at least one book on any programming language you can think of (or almost any IT and philosophy subject for that matter).

If anyone is looking for some material outside of physical books or websites with reviews, I'd be more than happy to share them; just send me a PM with your request.
Skype: divito7
billy5000
Profile Blog Joined December 2010
United States865 Posts
January 23 2012 12:19 GMT
#2168
guys, is it a bad habit to repetitively copy codes and try to reproduce it by yourself? Some of the examples in this book that my school uses just don't make sense to me. Like for instance, we're in intro to programming and we started to learn about conditionals and loops. As I'm reading my book, out of nowhere there are examples that convert numbers to binary numbers and betting simulations. Note that most of us do not have prior programming knowledge; we recently covered print statements, cmd arguments, converting data types, etc - the easy stuff.

While I do understand how the conditionals and loops work in such examples, I just can't seem to figure out the steps in between. I'm not even sure if we're supposed to understand it either.

For example:
http://introcs.cs.princeton.edu/java/13flow/Sqrt.java.html
http://introcs.cs.princeton.edu/java/13flow/Binary.java.html
http://introcs.cs.princeton.edu/java/13flow/Gambler.java.html

Like I understand what they do and how they are processed. But I'm not sure if we're supposed to have a deeper understanding, as if we're supposed to recreate a similar program to a particular example. However, even if we don't have to know exactly how everything's in place, I'm really curious as to how. The book doesn't really go in depth other than the fact that they have conditionals and loops.

Can anybody tutor me? i get the concepts that we cover in class, but these examples have a deeper understanding that I can't seem to grasp w/o help. and that deeper understanding is what I'm trying to get. if someone can offer a hand as a regular tutor just explaining how example-specific programs work throughout the semester via pm or w/e, that'd be great.

excuse my writing, it's 6 am here and we just had a tornado drill sometime around 4am which is why i am still awake, and holy shit my first 10am class prof just emailed me saying that class is cancelled as i have been typing this

tldr; I need a tutor who can help me throughout this semester for intro to programming in java. i went to some tutor sessions offered by my class, but they tell me that i don't need to know these stuff in-depth and acts like i'm a regular cs noob in need of noob type help. i have example-specific questions like the ones above. All of the examples are off this site: http://introcs.cs.princeton.edu/java/10elements/.
Tiger got to hunt, bird got to fly; Man got to sit and wonder, 'Why, why, why?' Tiger got to sleep, bird got to land; Man got to tell himself he understand. Vonnegut
ranshaked
Profile Blog Joined August 2010
United States870 Posts
January 23 2012 19:17 GMT
#2169
Hi guys! I'm stuck right now. I have to create a count that basically says "when it's true increase by 1" and stop once it hits 3.

for(i=1;i<=num;i++) I have something like that, but I'm not sure exactly how it works. The jist of the problem is this:

I have several if statements, which tell when a STATE will win in the electoral college. The last part I need to printf a statement that says "Your candidate can win in X ways" X ways will be the count. The program is running perfectly well, but I do not understand the counts. Do I have to put a count inside the IF statements?

This is all in basic C

Thanks <3
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
January 23 2012 21:56 GMT
#2170
This is not a question, just a whine from a low level programmer who works at a C compiler.

What the f*&% is up with heap allocation? If you ever wonder how your variables actually get stored in memory, take a look at the unix malloc/free implementations. protip: its easily too complicated for one person to comprehend all of what is going on.
Any sufficiently advanced technology is indistinguishable from magic
morty
Profile Joined July 2010
Germany38 Posts
January 23 2012 23:19 GMT
#2171
Nice Ruby Game and Motivation
lvl 8 begginer at the moment :

Online Version: http://www.trybloc.com/courses/ruby-warrior/chapters/beginner#/1

Download: https://github.com/ryanb/ruby-warrior/
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
January 23 2012 23:26 GMT
#2172
On January 24 2012 04:17 ranshaked wrote:
Hi guys! I'm stuck right now. I have to create a count that basically says "when it's true increase by 1" and stop once it hits 3.

for(i=1;i<=num;i++) I have something like that, but I'm not sure exactly how it works. The jist of the problem is this:

I have several if statements, which tell when a STATE will win in the electoral college. The last part I need to printf a statement that says "Your candidate can win in X ways" X ways will be the count. The program is running perfectly well, but I do not understand the counts. Do I have to put a count inside the IF statements?

This is all in basic C

Thanks <3


try to rephrase your question, i have not understand what your problem is at all.
Gold isn't everything in life... you need wood, too!
green.at
Profile Blog Joined January 2010
Austria1459 Posts
Last Edited: 2012-01-23 23:56:37
January 23 2012 23:30 GMT
#2173
On January 24 2012 04:17 ranshaked wrote:
Hi guys! I'm stuck right now. I have to create a count that basically says "when it's true increase by 1" and stop once it hits 3.

for(i=1;i<=num;i++) I have something like that, but I'm not sure exactly how it works. The jist of the problem is this:

I have several if statements, which tell when a STATE will win in the electoral college. The last part I need to printf a statement that says "Your candidate can win in X ways" X ways will be the count. The program is running perfectly well, but I do not understand the counts. Do I have to put a count inside the IF statements?

This is all in basic C

Thanks <3


if it is working perfectly fine and you just dont get it, why not debug it step by step? do you not unterstand the for() loop? oO
edit: and what MisterD above wrote ^^
edit2: is it that you do not know where to put the counter? if so you might have to post that part of your code
Inputting special characters into chat should no longer cause the game to crash.
ranshaked
Profile Blog Joined August 2010
United States870 Posts
January 24 2012 02:48 GMT
#2174
On January 24 2012 08:30 green.at wrote:
Show nested quote +
On January 24 2012 04:17 ranshaked wrote:
Hi guys! I'm stuck right now. I have to create a count that basically says "when it's true increase by 1" and stop once it hits 3.

for(i=1;i<=num;i++) I have something like that, but I'm not sure exactly how it works. The jist of the problem is this:

I have several if statements, which tell when a STATE will win in the electoral college. The last part I need to printf a statement that says "Your candidate can win in X ways" X ways will be the count. The program is running perfectly well, but I do not understand the counts. Do I have to put a count inside the IF statements?

This is all in basic C

Thanks <3


if it is working perfectly fine and you just dont get it, why not debug it step by step? do you not unterstand the for() loop? oO
edit: and what MisterD above wrote ^^
edit2: is it that you do not know where to put the counter? if so you might have to post that part of your code

I'm afraid to post it because it is homework and I'm not sure if they would consider that cheating?

Your candidate wins if he/she wins Florida.
Your candidate wins if he/she wins Indiana.
Your candidate wins if he/she wins Florida and Indiana.
Your candidate can win in 3 number of ways.


Those are the outputs for instance. I can get the first 3 outputs, but the last one "Your candidate can win 3 number of ways." isn't working. From what I understand I need to use a count in order to produce that output.
//Calculations
//int value; is this the right way to set it?
if (FIRSTSTATE+FIRSTCAN >= 270)
printf("You will win the election if you win %s.\n", &STATE1);
//value++ would it go like this?}
if (SECSTATE+FIRSTCAN >= 270)
printf("You will win the election if you win %s.\n", &STATE2);

if (FIRSTSTATE+SECSTATE+FIRSTCAN >= 270)
printf("You will win the election if you win %s and %s.\n", &STATE1, STATE2);


else if(FIRSTSTATE+SECSTATE+FIRSTCAN < 270)
printf("You cannot win this election even if you win %s and %s.\n", &STATE1, STATE2);

//printf("Your candidate can win %d ways.\n", &value); not sure exactly how to use ++value etc....


Here is the math part, basically I'm unsure of what to put within this section to get it to count if the "if's" pass. If it passes the first if, it will mean that you can win with just the first state and so forth. I can PM the entire code if you want to test it.

We haven't been taught how to "debug" yet aside from inserting printf's and testing line by line. I'm using Dev C++ compiler


I hope this helps a little.
chiboni
Profile Joined June 2011
15 Posts
Last Edited: 2012-01-24 15:06:49
January 24 2012 15:06 GMT
#2175
On January 24 2012 11:48 ranshaked wrote:
Show nested quote +
On January 24 2012 08:30 green.at wrote:
On January 24 2012 04:17 ranshaked wrote:
Hi guys! I'm stuck right now. I have to create a count that basically says "when it's true increase by 1" and stop once it hits 3.

for(i=1;i<=num;i++) I have something like that, but I'm not sure exactly how it works. The jist of the problem is this:

I have several if statements, which tell when a STATE will win in the electoral college. The last part I need to printf a statement that says "Your candidate can win in X ways" X ways will be the count. The program is running perfectly well, but I do not understand the counts. Do I have to put a count inside the IF statements?

This is all in basic C

Thanks <3


if it is working perfectly fine and you just dont get it, why not debug it step by step? do you not unterstand the for() loop? oO
edit: and what MisterD above wrote ^^
edit2: is it that you do not know where to put the counter? if so you might have to post that part of your code

I'm afraid to post it because it is homework and I'm not sure if they would consider that cheating?

Show nested quote +
Your candidate wins if he/she wins Florida.
Your candidate wins if he/she wins Indiana.
Your candidate wins if he/she wins Florida and Indiana.
Your candidate can win in 3 number of ways.


Those are the outputs for instance. I can get the first 3 outputs, but the last one "Your candidate can win 3 number of ways." isn't working. From what I understand I need to use a count in order to produce that output.
Show nested quote +
//Calculations
//int value; is this the right way to set it?
if (FIRSTSTATE+FIRSTCAN >= 270)
printf("You will win the election if you win %s.\n", &STATE1);
//value++ would it go like this?}
if (SECSTATE+FIRSTCAN >= 270)
printf("You will win the election if you win %s.\n", &STATE2);

if (FIRSTSTATE+SECSTATE+FIRSTCAN >= 270)
printf("You will win the election if you win %s and %s.\n", &STATE1, STATE2);


else if(FIRSTSTATE+SECSTATE+FIRSTCAN < 270)
printf("You cannot win this election even if you win %s and %s.\n", &STATE1, STATE2);

//printf("Your candidate can win %d ways.\n", &value); not sure exactly how to use ++value etc....


Here is the math part, basically I'm unsure of what to put within this section to get it to count if the "if's" pass. If it passes the first if, it will mean that you can win with just the first state and so forth. I can PM the entire code if you want to test it.

We haven't been taught how to "debug" yet aside from inserting printf's and testing line by line. I'm using Dev C++ compiler


I hope this helps a little.


So you want to count if one of the '>=270' conditions is true.
You have it almost solved!!


//initialize counter variable
int counter = 0; // <- always initalize variables with an value

//if this is true, increment counter by 1
if(...>=270) {
printf(...);
counter++; //<- you could also write it as 'counter = counter + 1;' or 'counter =+ 1'
}

//next condition and so on
...

//print value of counter
printf("...%i", counter);




ranshaked
Profile Blog Joined August 2010
United States870 Posts
January 24 2012 15:13 GMT
#2176
I got the count working Thanks guys. Now I have to loop the entire program and make it run X amount of times that the user inputs. It keeps crashing if I have the user input the number of times, but if I set the number of times by an int, it'll work fine.

DUN DUND DUN. I love this stuff. It's making my mind hurt. I'm glad I won't need this in my degree, but it's nice to know.

Thanksss
Adeny
Profile Blog Joined January 2009
Norway1233 Posts
January 24 2012 15:24 GMT
#2177
On January 25 2012 00:13 ranshaked wrote:
I got the count working Thanks guys. Now I have to loop the entire program and make it run X amount of times that the user inputs. It keeps crashing if I have the user input the number of times, but if I set the number of times by an int, it'll work fine.

DUN DUND DUN. I love this stuff. It's making my mind hurt. I'm glad I won't need this in my degree, but it's nice to know.

Thanksss


+ Show Spoiler +
I don't know which language you're working in but the user input is probably a string, and you're probably trying to shove it into an int. You need to look up int-parsing or -casting, depending on language.
tofucake
Profile Blog Joined October 2009
Hyrule19188 Posts
January 24 2012 15:27 GMT
#2178
it's C isn't it? Look into atoi
Liquipediaasante sana squash banana
WerderBremen
Profile Joined September 2011
Germany1070 Posts
Last Edited: 2012-01-24 15:36:07
January 24 2012 15:35 GMT
#2179
I'm missing low level language - assembler. I got decent knowledge about programming on x8086 and a few other 16 bit models. Anybody else here who is programming with low level language (even others than assembler)? Would be interesting to know.
"Thats the moment you send the kids outta the room - when you get contained by MarineKing." Tasteless
tofucake
Profile Blog Joined October 2009
Hyrule19188 Posts
January 24 2012 15:42 GMT
#2180
I'm not entirely sure what you just said.
Liquipediaasante sana squash banana
Prev 1 107 108 109 110 111 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 1h 46m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft470
NeuroSwarm 137
StarCraft: Brood War
actioN 298
zelot 137
ZergMaN 69
Larva 43
JulyZerg 33
Noble 19
Icarus 9
League of Legends
JimRising 756
C9.Mang0222
Counter-Strike
summit1g8591
Super Smash Bros
hungrybox457
Other Games
Livibee127
ViBE89
Organizations
Other Games
gamesdonequick4545
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 18 non-featured ]
StarCraft 2
• Berry_CruncH131
• practicex 40
• Kozan
• sooper7s
• AfreecaTV YouTube
• intothetv
• Migwel
• LaughNgamezSOOP
• IndyKCrew
StarCraft: Brood War
• iopq 6
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
League of Legends
• Scarra1532
• Rush1491
• Lourlo1138
• Stunt477
• HappyZerGling143
Upcoming Events
Replay Cast
1h 46m
Wardi Open
6h 46m
Monday Night Weeklies
9h 46m
WardiTV Invitational
1d 4h
WardiTV Invitational
2 days
The PondCast
3 days
OSC
3 days
OSC
4 days
All Star Teams
4 days
INnoVation vs soO
sOs vs Scarlett
uThermal 2v2 Circuit
5 days
[ Show More ]
All Star Teams
5 days
MMA vs DongRaeGu
Rogue vs Oliveira
Sparkling Tuna Cup
6 days
OSC
6 days
Liquipedia Results

Completed

Proleague 2026-01-11
Big Gabe Cup #3
NA Kuram Kup

Ongoing

C-Race Season 1
IPSL Winter 2025-26
BSL 21 Non-Korean Championship
CSL 2025 WINTER (S19)
OSC Championship Season 13
Underdog Cup #3
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025

Upcoming

Escore Tournament S1: W4
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Rongyi Cup S3
Thunderfire SC2 All-star 2025
Nations Cup 2026
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.