• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 19:37
CET 00:37
KST 08:37
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
ByuL: The Forgotten Master of ZvT29Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13Rongyi Cup S3 - Preview & Info8
Community News
Blizzard Classic Cup - Tastosis announced as captains6Weekly Cups (March 2-8): ByuN overcomes PvT block4GSL CK - New online series18BSL Season 224Vitality ends partnership with ONSYDE20
StarCraft 2
General
Blizzard Classic Cup - Tastosis announced as captains GSL CK - New online series Weekly Cups (March 2-8): ByuN overcomes PvT block Weekly Cups (Feb 23-Mar 1): herO doubles, 2v2 bonanza Vitality ends partnership with ONSYDE
Tourneys
[GSL CK] Team Maru vs. Team herO WardiTV Team League Season 10 Master Swan Open (Global Bronze-Master 2) RSL Season 4 announced for March-April Sparkling Tuna Cup - Weekly Open Tournament
Strategy
Custom Maps
Publishing has been re-enabled! [Feb 24th 2026] Map Editor closed ?
External Content
The PondCast: SC2 News & Results Mutation # 516 Specter of Death Mutation # 515 Together Forever Mutation # 514 Ulnar New Year
Brood War
General
ASL21 General Discussion Gypsy to Korea BGH Auto Balance -> http://bghmmr.eu/ Recent recommended BW games BSL 22 Map Contest — Submissions OPEN to March 10
Tourneys
[Megathread] Daily Proleagues IPSL Spring 2026 is here! ASL Season 21 Qualifiers March 7-8 BWCL Season 64 Announcement
Strategy
Soma's 9 hatch build from ASL Game 2 Fighting Spirit mining rates Simple Questions, Simple Answers Zealot bombing is no longer popular?
Other Games
General Games
PC Games Sales Thread Nintendo Switch Thread Path of Exile No Man's Sky (PS4 and PC) Stormgate/Frost Giant Megathread
Dota 2
Official 'what is Dota anymore' discussion The Story of Wings Gaming
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Five o'clock TL Mafia Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Mexico's Drug War Things Aren’t Peaceful in Palestine YouTube Thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Req][Books] Good Fantasy/SciFi books [Manga] One Piece
Sports
Formula 1 Discussion 2024 - 2026 Football Thread General nutrition recommendations Cricket [SPORT] TL MMA Pick'em Pool 2013
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
The Automated Ban List
Blogs
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
Gaming-Related Deaths
TrAiDoS
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1967 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 10h 24m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft498
SpeCial 112
ROOTCatZ 74
ProTech38
CosmosSc2 21
StarCraft: Brood War
Artosis 604
GuemChi 234
Aegong 41
NaDa 28
LancerX 14
IntoTheRainbow 12
Dota 2
monkeys_forever262
Counter-Strike
fl0m819
taco 326
Super Smash Bros
AZ_Axe130
Other Games
summit1g12435
Grubby2866
FrodaN908
shahzam720
C9.Mang0173
Mew2King85
ViBE69
Organizations
Other Games
gamesdonequick1960
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• EnkiAlexander 8
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• masondota21627
League of Legends
• Doublelift6459
Other Games
• imaqtpie1324
Upcoming Events
The PondCast
10h 24m
WardiTV Team League
12h 24m
Replay Cast
1d
Replay Cast
2 days
CranKy Ducklings
2 days
RSL Revival
2 days
WardiTV Team League
2 days
uThermal 2v2 Circuit
2 days
BSL
2 days
Sparkling Tuna Cup
3 days
[ Show More ]
RSL Revival
3 days
WardiTV Team League
3 days
BSL
3 days
Replay Cast
4 days
Replay Cast
4 days
Wardi Open
4 days
Monday Night Weeklies
4 days
WardiTV Team League
5 days
GSL
6 days
Liquipedia Results

Completed

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

Ongoing

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

Upcoming

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