• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 08:50
CEST 14:50
KST 21:50
  • 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
[ASL19] Finals Recap: Standing Tall9HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Flash Announces Hiatus From ASL62Weekly Cups (June 23-29): Reynor in world title form?13FEL Cracov 2025 (July 27) - $8000 live event21Esports World Cup 2025 - Final Player Roster16Weekly Cups (June 16-22): Clem strikes back1
StarCraft 2
General
Program: SC2 / XSplit / OBS Scene Switcher The SCII GOAT: A statistical Evaluation Statistics for vetoed/disliked maps Weekly Cups (June 23-29): Reynor in world title form? PiG Sty Festival #5: Playoffs Preview + Groups Recap
Tourneys
RSL: Revival, a new crowdfunded tournament series Sparkling Tuna Cup - Weekly Open Tournament WardiTV Mondays FEL Cracov 2025 (July 27) - $8000 live event Korean Starcraft League Week 77
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma Mutation # 477 Slow and Steady
Brood War
General
Player “Jedi” cheat on CSL SC uni coach streams logging into betting site Flash Announces Hiatus From ASL Practice Partners (Official) ASL20 Preliminary Maps
Tourneys
[BSL20] Grand Finals - Sunday 20:00 CET [Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL20] GosuLeague RO16 - Tue & Wed 20:00+CET
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread Nintendo Switch Thread What do you want from future RTS games? 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
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Summer Games Done Quick 2025! Trading/Investing Thread Things Aren’t Peaceful in Palestine
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2025 Football Thread Formula 1 Discussion NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Blogs
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 622 users

The Big Programming Thread - Page 109

Forum Index > General Forum
Post a Reply
Prev 1 107 108 109 110 111 1031 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
Hyrule19030 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
Hyrule19030 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 1031 Next
Please log in or register to reply.
Live Events Refresh
WardiTV European League
12:00
Swiss Groups Day 2
WardiTV744
TKL 431
Liquipedia
FEL
12:00
Cracov 2025: Qualifier #2
IndyStarCraft 310
CranKy Ducklings79
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
TKL 431
IndyStarCraft 310
Rex 119
MindelVK 39
StarCraft: Brood War
Sea 11032
Calm 9514
Rain 7180
Bisu 2849
Horang2 2292
Hyuk 1365
Jaedong 1317
Shuttle 516
Rush 430
EffOrt 300
[ Show more ]
Stork 282
Leta 270
Last 240
PianO 210
Mini 206
ToSsGirL 156
Hyun 140
ZerO 95
Movie 79
hero 55
TY 53
Sea.KH 41
JYJ40
Killer 35
JulyZerg 29
ajuk12(nOOB) 22
HiyA 20
GoRush 19
Free 19
zelot 19
Terrorterran 18
Sacsri 17
Barracks 16
Icarus 6
ivOry 2
Stormgate
NightEnD21
Dota 2
qojqva3057
XcaliburYe452
canceldota102
League of Legends
singsing2904
Counter-Strike
x6flipin739
zeus453
Heroes of the Storm
Khaldor315
Other Games
Gorgc2822
B2W.Neo1375
DeMusliM540
Happy390
Fuzer 389
crisheroes369
Pyrionflax337
XaKoH 263
Hui .243
RotterdaM147
ArmadaUGS70
KnowMe60
ZerO(Twitch)17
Organizations
StarCraft: Brood War
CasterMuse 25
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• StrangeGG 38
• iHatsuTV 6
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• WagamamaTV749
• Ler42
Upcoming Events
BSL: ProLeague
5h 10m
Dewalt vs Bonyth
Replay Cast
1d 11h
Sparkling Tuna Cup
1d 21h
WardiTV European League
2 days
The PondCast
2 days
Replay Cast
3 days
RSL Revival
3 days
ByuN vs SHIN
Clem vs Reynor
Replay Cast
4 days
RSL Revival
4 days
Classic vs Cure
FEL
5 days
[ Show More ]
RSL Revival
5 days
FEL
5 days
FEL
6 days
Sparkling Tuna Cup
6 days
RSL Revival
6 days
Liquipedia Results

Completed

BSL 2v2 Season 3
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL Season 20
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
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.