• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 17:49
CEST 23:49
KST 06:49
  • 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
Code S Season 1 - RO8 Preview3[ASL21] Ro8 Preview Pt2: Progenitors8Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun13[ASL21] Ro8 Preview Pt1: Inheritors16[ASL21] Ro16 Preview Pt2: All Star10
Community News
Weekly Cups (April 27-May 4): Clem takes triple0RSL Revival: Season 5 - Qualifiers and Main Event11Code S Season 1 (2026) - RO12 Results12026 GSL Season 1 Qualifiers25Maestros of the Game 2 announced9
StarCraft 2
General
Code S Season 1 - RO8 Preview Behind the Blue - Team Liquid History Book Weekly Cups (April 27-May 4): Clem takes triple Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Code S Season 1 (2026) - RO12 Results
Tourneys
GSL Code S Season 1 (2026) Sparkling Tuna Cup - Weekly Open Tournament RSL Revival: Season 5 - Qualifiers and Main Event StarCraft Evolution League (SC Evo Biweekly) 2026 GSL Season 2 Qualifiers
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
Mutation # 524 Death and Taxes The PondCast: SC2 News & Results Mutation # 523 Firewall Mutation # 522 Flip My Base
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ (Spoiler) Asl ro8 D winner interview BW General Discussion Do we have a pimpest plays list? AI Question
Tourneys
[ASL21] Ro8 Day 4 [ASL21] Ro8 Day 3 [Megathread] Daily Proleagues [ASL21] Ro8 Day 2
Strategy
Simple Questions, Simple Answers Fighting Spirit mining rates What's the deal with APM & what's its true value Any training maps people recommend?
Other Games
General Games
Dawn of War IV Stormgate/Frost Giant Megathread OutLive 25 (RTS Game) Daigo vs Menard Best of 10 Nintendo Switch Thread
Dota 2
The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread European Politico-economics QA Mega-thread 3D technology/software discussion Canadian Politics Mega-thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [Req][Books] Good Fantasy/SciFi books
Sports
2024 - 2026 Football Thread Formula 1 Discussion McBoner: A hockey love story
World Cup 2022
Tech Support
streaming software Strange computer issues (software) [G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Movie Stars In Video Games: …
TrAiDoS
ramps on octagon
StaticNine
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2354 users

The Big Programming Thread - Page 157

Forum Index > General Forum
Post a Reply
Prev 1 155 156 157 158 159 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.
SiPa
Profile Joined July 2010
Germany129 Posts
August 17 2012 13:02 GMT
#3121
wow thanks so much!
at least VS2010 thinks it's cool (still producing mass errors, when trying to compile, but i will tend to them after fixing all the red underlined stuffs ^^)
omarsito
Profile Joined June 2011
22 Posts
August 17 2012 16:11 GMT
#3122
Hey tlers, got a quick question about eclipse. I cant find the option to increase the "code window" (check picture) without dragging the slider.

http://imgur.com/5D46K

If anybody has the answer please pm or just reply! thanks.
MisterD
Profile Blog Joined June 2010
Germany1338 Posts
August 17 2012 17:04 GMT
#3123
On August 18 2012 01:11 omarsito wrote:
Hey tlers, got a quick question about eclipse. I cant find the option to increase the "code window" (check picture) without dragging the slider.

http://imgur.com/5D46K

If anybody has the answer please pm or just reply! thanks.


try "reset perspective" from the window menu.
Gold isn't everything in life... you need wood, too!
Thorakh
Profile Joined April 2011
Netherlands1788 Posts
Last Edited: 2012-08-19 20:48:51
August 19 2012 20:37 GMT
#3124
Java code!

Why oh why is this

+ Show Spoiler +
import java.util.*;

public class RunProgram
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int a = 0;
boolean correctAnswer = false;

while (!correctAnswer)
{
System.out.println("Please enter an integer:");
try
{
a = sc.nextInt();
correctAnswer = true;
}
catch (Exception e)
{
System.out.println("You didn't enter an integer!");
}
}

System.out.println("int = " + a);
}
}


giving me this

+ Show Spoiler +
Please enter an integer:
b
You didn't enter an integer!
Please enter an integer:
You didn't enter an integer!
Please enter an integer:
You didn't enter an integer!
Please enter an integer:
You didn't enter an integer!
Please enter an integer:
You didn't enter an integer!
...


as console output? I suspect it has something to do with the Scanner because

+ Show Spoiler +
import java.util.*;

public class RunProgram
{
public static void main(String[] args)
{
int a = 0;
boolean correctAnswer = false;

while (!correctAnswer)
{
System.out.println("Please enter an integer:");
try
{
Scanner sc = new Scanner(System.in);
a = sc.nextInt();
sc.close();
correctAnswer = true;
}
catch (Exception e)
{
System.out.println("You didn't enter an integer!");
}
}

System.out.println("int = " + a);
}
}


gives me

+ Show Spoiler +
Please enter an integer:
b
You didn't enter an integer!
Please enter an integer:


as expected.

Why do I have to generate a new Scanner object for this to work?

I am 100% sure I am making a dumb mistake here but I can't for the life of me seem to figure it out! I'm completely stumped.
beamerkun
Profile Joined December 2009
Poland112 Posts
August 19 2012 20:55 GMT
#3125
You're leaving that 'b' character in buffer - look that in second example you make a new scanner (thus, a new buffer) every time somebody enters line.
Evolution is complete!
Thorakh
Profile Joined April 2011
Netherlands1788 Posts
Last Edited: 2012-08-19 21:10:04
August 19 2012 21:05 GMT
#3126
On August 20 2012 05:55 beamerkun wrote:
You're leaving that 'b' character in buffer - look that in second example you make a new scanner (thus, a new buffer) every time somebody enters line.
Ah, of course! Is there a more elegant solution than adding a variable that simply 'eats' the incorrect input

+ Show Spoiler +
import java.util.*;

public class RunProgram
{

public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int a = 0;
boolean correctAnswer = false;
String rubbish = "";

while (!correctAnswer)
{
System.out.println("Please enter an integer:");
try
{
a = sc.nextInt();

correctAnswer = true;
}
catch (Exception e)
{
System.out.println("You didn't enter an integer!");
rubbish = sc.next();
}
}

System.out.println("int = " + a);
}
}


or is making a new Scanner object and closing it every loop an acceptable solution?
Kambing
Profile Joined May 2010
United States1176 Posts
August 19 2012 21:47 GMT
#3127
On August 20 2012 06:05 Thorakh wrote:
Show nested quote +
On August 20 2012 05:55 beamerkun wrote:
You're leaving that 'b' character in buffer - look that in second example you make a new scanner (thus, a new buffer) every time somebody enters line.
Ah, of course! Is there a more elegant solution than adding a variable that simply 'eats' the incorrect input

+ Show Spoiler +
import java.util.*;

public class RunProgram
{

public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int a = 0;
boolean correctAnswer = false;
String rubbish = "";

while (!correctAnswer)
{
System.out.println("Please enter an integer:");
try
{
a = sc.nextInt();

correctAnswer = true;
}
catch (Exception e)
{
System.out.println("You didn't enter an integer!");
rubbish = sc.next();
}
}

System.out.println("int = " + a);
}
}


or is making a new Scanner object and closing it every loop an acceptable solution?


The rubbish variable is unnecessary. You can simply call sc.next() to consume the offending input without storing the returned value in a variable. Note you are only creating one Scanner object here (connected to System.in).

Probably more importantly is that using a try-catch to handle the case where the input is not an integer is not good style. Instead, you should use the hasNextInt() method of the Scanner class to test to see if the next token in the input stream is an integer. If it is not, then you can repeatedly prompt the user until they enter a number.

(Note that ripping out input from System.in by token is a little weird as it is not entirely clear when the prompting occurs. You could argue that it would be better to use readLine() to explicitly grab a line of input from the user and then test that resulting String to see if it is an integer.)
green.at
Profile Blog Joined January 2010
Austria1459 Posts
August 19 2012 21:59 GMT
#3128
Does it work if you use sc.flush()? Also, you could use a regex to check if the input is valid.
Inputting special characters into chat should no longer cause the game to crash.
Kambing
Profile Joined May 2010
United States1176 Posts
August 19 2012 22:04 GMT
#3129
Scanner objects don't have a flush method. And using a regex to check input well-formedness is overkill if all he's looking to enforce is that the input is a valid integer.
white_horse
Profile Joined July 2010
1019 Posts
Last Edited: 2012-08-20 02:02:51
August 20 2012 02:01 GMT
#3130
Ok I'm trying to make a program that outputs 100 random lowercase letters in rows of 10. I got this far below,but when "I run the program, it ouputs nothing. Can you guys help me? thanks


+ Show Spoiler +

#include <iostream>
#include <cstdlib>
using namespace std;

void randomgen(char ch1, char ch2)
{
for(int i = 1; i <= 100; i++)
{
cout << static_cast<char>('ch1' + rand() % ('ch2' - 'ch1' + 1));
cout << " ";
if (i % 10 == 0)
{
cout << endl;
}
}
}


int main()
{
char a, z;
randomgen(a, z);


return 0;

}


edit: It's not letting me indent any of the code -_-
Translator
tec27
Profile Blog Joined June 2004
United States3702 Posts
August 20 2012 02:20 GMT
#3131
Use code tags.

But anyway, first thing, you shouldn't be single-quoting your variable names, single quotes are only for char literals. Secondly, you never initialized your a and z variables. If you intend them to be equal to 'a' and 'z', you need to do something like:
char a = 'a';
char z = 'z';


Alternatively you could just pass those values in ( randomgen('a', 'z') ) and not store them in variables.

Judging from your code, it looks like you don't quite understand the difference between variable names and variable values. Variable names are like an address on a mailbox. They tell the compiler what location you're referring to, but the compiler can make no assumptions from the name as to what the location contains. Thus, if you have a char variable named 'a', for all the compiler knows you're storing the value 'f' there. Similarly, if you quote a variable name as a literal (IE: 'ch2' in your code) the compiler will look at this as a literal and nothing else. It will not replace this with either value or the name of what was passed into your function.
Can you jam with the console cowboys in cyberspace?
IreScath
Profile Joined May 2009
Canada521 Posts
August 21 2012 16:50 GMT
#3132
I can't figure this out.. When using WaitWindow or WaitWindowLike in my Perl module... It doesn't wait for the app that is launching

code:


my $pid = StartApp("D:\\Musemage\\Musemage.exe");
print 'Launching app.';

#the following should wait for 30 seconds for the app to appear, then continue.
WaitWindow("Musemage",30);

print 'Found window.';
print $pid;




I've also tried WaitWindowLike() to no avail. Its not even like the app just isnt launching.. It is, however the program never waits and just prints 'found window' immediately.

output when run:


Starting [D:\Musemage\Musemage.exe]
new pid:=5372
Launching app.Found window.5372


After Launching app, the script should wait until Musemage window has launched (takes about 8 seconds), and THEN out put the rest... however "found window.5372" prints the same time as "launching app", then the perl script finishes... THEN about 4 seconds after that Musemage finally opens.

The only thing I'm thinking is I'm using WaitWindow wrong? I've tested with wait time at 3 - 3000000.
IreScath
IreScath
Profile Joined May 2009
Canada521 Posts
August 21 2012 16:52 GMT
#3133
I should also note that the WaitWindow function just calls Win32::GuiTest::WaitWindow(@_);
IreScath
supereddie
Profile Joined March 2011
Netherlands151 Posts
August 21 2012 17:05 GMT
#3134
There is a difference between the app loading and the app creating it's main window. The window can be created immediately (and hidden) while the app actually loads. I assume WaitWindow finds the hidden window.

Additionally, WaitWindow has a return value. try print_r(WaitWindow(.....)) to see what it returns; I guess it is an array of window handles that match the name.
"Do not try to make difficult things possible, but make simple things simple." - David Platt on Software Design
SilSol
Profile Joined April 2012
Sweden2744 Posts
August 21 2012 17:08 GMT
#3135
I wish i could do programming! That'd be awesome Maybe someone could teach me the basics?
http://fragbite.se/user/117868/silsol since 2006 http://www.reddit.com/u/silsol77
IreScath
Profile Joined May 2009
Canada521 Posts
August 21 2012 17:19 GMT
#3136
On August 22 2012 02:05 supereddie wrote:
There is a difference between the app loading and the app creating it's main window. The window can be created immediately (and hidden) while the app actually loads. I assume WaitWindow finds the hidden window.

Additionally, WaitWindow has a return value. try print_r(WaitWindow(.....)) to see what it returns; I guess it is an array of window handles that match the name.



Yea I think you are correct... Its spitting a number out (5835818 for example)... Anyone know of a wait to wait until the window is actually loaded up and visible?
IreScath
supereddie
Profile Joined March 2011
Netherlands151 Posts
August 21 2012 17:25 GMT
#3137
There probably is a way to query the visibility of a window by using the window handle - check the Perl docs.

@SilSol: You start by thinking logically and linear; both in detail (individual lines/code blocks/methods) and in the large scale (complete program or even interfacing with other programs). If you can do that, you have the basics.
"Do not try to make difficult things possible, but make simple things simple." - David Platt on Software Design
white_horse
Profile Joined July 2010
1019 Posts
August 21 2012 18:00 GMT
#3138
On August 20 2012 11:20 tec27 wrote:
Use code tags.

But anyway, first thing, you shouldn't be single-quoting your variable names, single quotes are only for char literals. Secondly, you never initialized your a and z variables. If you intend them to be equal to 'a' and 'z', you need to do something like:
char a = 'a';
char z = 'z';


Alternatively you could just pass those values in ( randomgen('a', 'z') ) and not store them in variables.

Judging from your code, it looks like you don't quite understand the difference between variable names and variable values. Variable names are like an address on a mailbox. They tell the compiler what location you're referring to, but the compiler can make no assumptions from the name as to what the location contains. Thus, if you have a char variable named 'a', for all the compiler knows you're storing the value 'f' there. Similarly, if you quote a variable name as a literal (IE: 'ch2' in your code) the compiler will look at this as a literal and nothing else. It will not replace this with either value or the name of what was passed into your function.


that helped thanks
Translator
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
August 21 2012 18:32 GMT
#3139
On August 22 2012 02:25 supereddie wrote:
There probably is a way to query the visibility of a window by using the window handle - check the Perl docs.

@SilSol: You start by thinking logically and linear; both in detail (individual lines/code blocks/methods) and in the large scale (complete program or even interfacing with other programs). If you can do that, you have the basics.


I usually tell people to basically think about how they would solve a given problem by hand with pen&paper, then write it down step by step and after that turn every step into the corresponding code. The end result might not be perfect code or the best and fastest solution but it is a solution that works.

Many people think of programming like something complex and obscure which scares them off since programmers tend to always talk about optimization, ideal sorting algorithms, program design, database normalization, RAII, OOP and all that stuff. Once they understand that programs actually just do stuff you would do yourself, just that computers do it a billion times faster, it gets easier for them to actually turn problems into codified solutions since they no longer try to understand programming but instead start to understand solving problems.
supereddie
Profile Joined March 2011
Netherlands151 Posts
Last Edited: 2012-08-21 19:00:30
August 21 2012 19:00 GMT
#3140
Yup, programming is more about problem solving (and analyzing) than writing code. Learning the syntax, keywords and specifics of your programming language is useful, but if you can't solve problems you won't be able to write any :p
"Do not try to make difficult things possible, but make simple things simple." - David Platt on Software Design
Prev 1 155 156 157 158 159 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 11h 41m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 481
PiGStarcraft95
StarCraft: Brood War
Britney 12593
Mini 175
Dewaltoss 103
Aegong 50
NaDa 7
Dota 2
monkeys_forever381
Other Games
Grubby4588
tarik_tv4521
Liquid`RaSZi1641
fl0m1225
shahzam390
C9.Mang0190
uThermal169
Liquid`Hasu160
ArmadaUGS117
UpATreeSC57
ZombieGrub41
ToD12
Organizations
Other Games
BasetradeTV504
Dota 2
PGL Dota 2 - Main Stream25
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 14 non-featured ]
StarCraft 2
• Reevou 6
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• masondota2959
League of Legends
• imaqtpie2269
Other Games
• Shiphtur393
Upcoming Events
GSL
11h 41m
SHIN vs Zoun
ByuN vs herO
OSC
13h 11m
OSC
15h 11m
Replay Cast
1d 2h
Escore
1d 12h
The PondCast
1d 12h
WardiTV Invitational
1d 13h
Zoun vs Ryung
Lambo vs ShoWTimE
Big Brain Bouts
1d 18h
Fjant vs Bly
Serral vs Shameless
OSC
2 days
Replay Cast
2 days
[ Show More ]
CranKy Ducklings
2 days
RSL Revival
2 days
SHIN vs Bunny
ByuN vs Shameless
WardiTV Invitational
2 days
Krystianer vs TriGGeR
Cure vs Rogue
uThermal 2v2 Circuit
2 days
BSL
2 days
Replay Cast
3 days
Sparkling Tuna Cup
3 days
RSL Revival
3 days
Cure vs Zoun
Clem vs Lambo
WardiTV Invitational
3 days
BSL
3 days
GSL
4 days
Afreeca Starleague
4 days
Soma vs Leta
Monday Night Weeklies
4 days
CranKy Ducklings
5 days
Afreeca Starleague
5 days
Light vs Flash
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2026-05-05
WardiTV TLMC #16
Nations Cup 2026

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
KCM Race Survival 2026 Season 2
Acropolis #4
YSL S3
SCTL 2026 Spring
RSL Revival: Season 5
2026 GSL S1
BLAST Rivals Spring 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026

Upcoming

Escore Tournament S2: W6
KK 2v2 League Season 1
BSL 22 Non-Korean Championship
Escore Tournament S2: W7
Escore Tournament S2: W8
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
2026 GSL S2
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 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.