• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 02:04
CET 07:04
KST 15:04
  • 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
ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13Rongyi Cup S3 - Preview & Info8
Community News
2026 KongFu Cup Announcement0BGE Stara Zagora 2026 cancelled10Blizzard Classic Cup - Tastosis announced as captains12Weekly Cups (March 2-8): ByuN overcomes PvT block4GSL CK - New online series18
StarCraft 2
General
BGE Stara Zagora 2026 cancelled BGE Stara Zagora 2026 announced ByuL: The Forgotten Master of ZvT Terran AddOns placement Blizzard Classic Cup - Tastosis announced as captains
Tourneys
2026 KongFu Cup Announcement [GSL CK] Team Maru vs. Team herO StarCraft Evolution League (SC Evo Biweekly) WardiTV Team League Season 10 Master Swan Open (Global Bronze-Master 2)
Strategy
Custom Maps
Publishing has been re-enabled! [Feb 24th 2026] Map Editor closed ?
External Content
The PondCast: SC2 News & Results Mutation # 516 Specter of Death Mutation # 515 Together Forever Mutation # 514 Ulnar New Year
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ ASL21 General Discussion BW General Discussion Gypsy to Korea Are you ready for ASL 21? Hype VIDEO
Tourneys
[Megathread] Daily Proleagues [BSL22] Open Qualifiers & Ladder Tours IPSL Spring 2026 is here! ASL Season 21 Qualifiers March 7-8
Strategy
Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2 Fighting Spirit mining rates Zealot bombing is no longer popular?
Other Games
General Games
Stormgate/Frost Giant Megathread Path of Exile Nintendo Switch Thread PC Games Sales Thread No Man's Sky (PS4 and PC)
Dota 2
Official 'what is Dota anymore' discussion The Story of Wings Gaming
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
Five o'clock TL Mafia Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread Mexico's Drug War Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread NASA and the Private Sector
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Movie Discussion! [Req][Books] Good Fantasy/SciFi books [Manga] One Piece
Sports
Formula 1 Discussion 2024 - 2026 Football Thread General nutrition recommendations Cricket [SPORT] TL MMA Pick'em Pool 2013
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
The Automated Ban List
Blogs
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
Gaming-Related Deaths
TrAiDoS
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1762 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
Hyrule19194 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
Hyrule19194 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
Replay Cast
00:00
Code For Giants Cup #28
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Nina 140
ProTech130
SortOf 37
StarCraft: Brood War
Britney 27889
ToSsGirL 80
Dota 2
NeuroSwarm181
resolut1ontv 150
League of Legends
JimRising 677
Counter-Strike
Stewie2K790
Super Smash Bros
Mew2King101
Other Games
summit1g9215
C9.Mang0553
WinterStarcraft373
RuFF_SC241
Liquid`Ken19
Organizations
Other Games
gamesdonequick1258
ComeBackTV 95
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• practicex 27
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Lourlo2756
• Scarra2606
• Stunt416
Upcoming Events
CranKy Ducklings
3h 57m
RSL Revival
3h 57m
MaxPax vs Rogue
Clem vs Bunny
WardiTV Team League
5h 57m
uThermal 2v2 Circuit
10h 57m
BSL
13h 57m
Sparkling Tuna Cup
1d 3h
RSL Revival
1d 3h
ByuN vs SHIN
Maru vs Krystianer
WardiTV Team League
1d 5h
Patches Events
1d 10h
BSL
1d 13h
[ Show More ]
Replay Cast
1d 17h
Replay Cast
2 days
Wardi Open
2 days
Monday Night Weeklies
2 days
OSC
2 days
WardiTV Team League
3 days
GSL
4 days
The PondCast
5 days
WardiTV Team League
5 days
Replay Cast
5 days
WardiTV Team League
6 days
Korean StarCraft League
6 days
Liquipedia Results

Completed

Proleague 2026-03-13
WardiTV Winter 2026
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
Jeongseon Sooper Cup
BSL Season 22
RSL Revival: Season 4
Nations Cup 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual

Upcoming

CSL Elite League 2026
ASL Season 21
Acropolis #4 - TS6
2026 Changsha Offline CUP
Acropolis #4
IPSL Spring 2026
CSLAN 4
HSC XXIX
uThermal 2v2 2026 Main Event
NationLESS Cup
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
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.