• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 21:50
CEST 03:50
KST 10: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
[ASL20] Ro8 Preview Pt1: Mile High11Team TLMC #5 - Finalists & Open Tournaments2[ASL20] Ro16 Preview Pt2: Turbulence10Classic Games #3: Rogue vs Serral at BlizzCon10[ASL20] Ro16 Preview Pt1: Ascent10
Community News
StarCraft II 5.0.15 PTR Patch Notes192BSL 2025 Warsaw LAN + Legends Showmatch2Weekly Cups (Sept 8-14): herO & MaxPax split cups4WardiTV TL Team Map Contest #5 Tournaments1SC4ALL $6,000 Open LAN in Philadelphia8
StarCraft 2
General
StarCraft II 5.0.15 PTR Patch Notes Why Storm Should NOT Be Nerfed – A Core Part of Pr #1: Maru - Greatest Players of All Time SC4ALL: A North American StarCraft LAN Team TLMC #5 - Finalists & Open Tournaments
Tourneys
RSL: Revival, a new crowdfunded tournament series SC2's Safe House 2 - October 18 & 19 Stellar Fest KSL Week 80 StarCraft Evolution League (SC Evo Biweekly)
Strategy
Custom Maps
External Content
Mutation # 492 Get Out More Mutation # 491 Night Drive Mutation # 490 Masters of Midnight Mutation # 489 Bannable Offense
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ Old rep packs of BW legends ASL ro8 Upper Bracket HYPE VIDEO [ASL20] Ro8 Preview Pt1: Mile High BW General Discussion
Tourneys
[ASL20] Ro16 Group D SC4ALL $1,500 Open Bracket LAN BSL 2025 Warsaw LAN + Legends Showmatch [ASL20] Ro16 Group C
Strategy
Simple Questions, Simple Answers Muta micro map competition
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile Borderlands 3 General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
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
Community
General
US Politics Mega-thread The Big Programming Thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread UK Politics Mega-thread
Fan Clubs
The Happy Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion MLB/Baseball 2023
World Cup 2022
Tech Support
Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread High temperatures on bridge(s)
TL Community
BarCraft in Tokyo Japan for ASL Season5 Final The Automated Ban List
Blogs
Why can't Americans stop ea…
Peanutsc
Too Many LANs? Tournament Ov…
TrAiDoS
I <=> 9
KrillinFromwales
A very expensive lesson on ma…
Garnet
hello world
radishsoup
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1671 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
Hyrule19091 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
Hyrule19091 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 8h 10m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
NeuroSwarm 143
RuFF_SC2 109
StarCraft: Brood War
Artosis 849
Sharp 38
NaDa 16
Dota 2
capcasts372
League of Legends
Cuddl3bear4
Heroes of the Storm
Khaldor160
Other Games
summit1g10287
JimRising 544
C9.Mang0218
Maynarde136
Mew2King38
Organizations
Other Games
gamesdonequick694
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 12 non-featured ]
StarCraft 2
• Berry_CruncH237
• davetesta34
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Upcoming Events
Afreeca Starleague
8h 10m
Barracks vs Mini
Wardi Open
9h 10m
Monday Night Weeklies
14h 10m
Sparkling Tuna Cup
1d 8h
Afreeca Starleague
1d 8h
Snow vs EffOrt
PiGosaur Monday
1d 22h
LiuLi Cup
2 days
The PondCast
3 days
CranKy Ducklings
4 days
Maestros of the Game
5 days
Clem vs Reynor
[ Show More ]
[BSL 2025] Weekly
5 days
[BSL 2025] Weekly
5 days
BSL Team Wars
6 days
Liquipedia Results

Completed

2025 Chongqing Offline CUP
RSL Revival: Season 2
HCC Europe

Ongoing

BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
Maestros of the Game
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

Upcoming

IPSL Winter 2025-26
SC4ALL: Brood War
BSL 21 Team A
BSL Season 21
Stellar Fest
SC4ALL: StarCraft II
EC S1
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
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.