• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 14:04
CET 20:04
KST 04: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
RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13
Community News
[TLMC] Fall/Winter 2025 Ladder Map Rotation12Weekly Cups (Nov 3-9): Clem Conquers in Canada4SC: Evo Complete - Ranked Ladder OPEN ALPHA8StarCraft, SC2, HotS, WC3, Returning to Blizzcon!45$5,000+ WardiTV 2025 Championship7
StarCraft 2
General
Mech is the composition that needs teleportation t RotterdaM "Serral is the GOAT, and it's not close" RSL Season 3 - RO16 Groups C & D Preview [TLMC] Fall/Winter 2025 Ladder Map Rotation TL.net Map Contest #21: Winners
Tourneys
RSL Revival: Season 3 Sparkling Tuna Cup - Weekly Open Tournament Constellation Cup - Main Event - Stellar Fest Tenacious Turtle Tussle Master Swan Open (Global Bronze-Master 2)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection
Brood War
General
FlaSh on: Biggest Problem With SnOw's Playstyle What happened to TvZ on Retro? SnOw's ASL S20 Finals Review BW General Discussion Brood War web app to calculate unit interactions
Tourneys
[Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL21] RO32 Group D - Sunday 21:00 CET [BSL21] RO32 Group C - Saturday 21:00 CET
Strategy
PvZ map balance Current Meta Simple Questions, Simple Answers How to stay on top of macro?
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread Nintendo Switch Thread Clair Obscur - Expedition 33 Beyond All Reason
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
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread US Politics Mega-thread Artificial Intelligence Thread Canadian Politics Mega-thread
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Dyadica Gospel – a Pulp No…
Hildegard
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Reality "theory" prov…
perfectspheres
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2010 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
Hyrule19152 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
Hyrule19152 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
OSC
19:00
Masters Cup #150: Group B
davetesta28
Liquipedia
IPSL
17:00
Ro16 Group D
ZZZero vs rasowy
Napoleon vs KameZerg
Liquipedia
PSISTORM Gaming Misc
15:55
FSL teamleague CNvsASH, ASHvRR
Freeedom44
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Railgan 177
IndyStarCraft 124
BRAT_OK 50
MindelVK 33
EmSc Tv 12
StarCraft: Brood War
Britney 20672
Calm 2244
Shuttle 809
Dewaltoss 128
Rock 52
Shine 40
NaDa 12
Dota 2
Gorgc5065
qojqva1662
Dendi976
League of Legends
rGuardiaN39
Counter-Strike
ScreaM1188
byalli487
Heroes of the Storm
Khaldor521
Other Games
tarik_tv5004
gofns2159
Beastyqt556
DeMusliM332
Grubby254
Lowko200
Fuzer 200
Organizations
Dota 2
PGL Dota 2 - Main Stream7478
Other Games
EGCTV796
gamesdonequick575
StarCraft 2
EmSc Tv 12
EmSc2Tv 12
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 19 non-featured ]
StarCraft 2
• printf 39
• IndyKCrew
• sooper7s
• AfreecaTV YouTube
• Migwel
• intothetv
• LaughNgamezSOOP
• Kozan
StarCraft: Brood War
• Airneanach44
• HerbMon 15
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 3173
• WagamamaTV394
• Ler87
League of Legends
• Nemesis3842
Other Games
• imaqtpie1387
• Shiphtur301
Upcoming Events
BSL 21
56m
Tarson vs Julia
Doodle vs OldBoy
eOnzErG vs WolFix
StRyKeR vs Aeternum
Sparkling Tuna Cup
14h 56m
RSL Revival
14h 56m
Reynor vs sOs
Maru vs Ryung
Kung Fu Cup
16h 56m
Cure vs herO
Reynor vs TBD
WardiTV Korean Royale
16h 56m
BSL 21
1d
JDConan vs Semih
Dragon vs Dienmax
Tech vs NewOcean
TerrOr vs Artosis
IPSL
1d
Dewalt vs WolFix
eOnzErG vs Bonyth
Replay Cast
1d 3h
Wardi Open
1d 16h
Monday Night Weeklies
1d 21h
[ Show More ]
WardiTV Korean Royale
2 days
BSL: GosuLeague
3 days
The PondCast
3 days
Replay Cast
4 days
RSL Revival
4 days
BSL: GosuLeague
5 days
RSL Revival
5 days
WardiTV Korean Royale
5 days
RSL Revival
6 days
WardiTV Korean Royale
6 days
IPSL
6 days
Julia vs Artosis
JDConan vs DragOn
Liquipedia Results

Completed

Proleague 2025-11-14
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
CSCL: Masked Kings S3
SLON Tour Season 2
RSL Revival: Season 3
META Madness #9
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
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 © 2025 TLnet. All Rights Reserved.