• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 03:15
CEST 09:15
KST 16:15
  • 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
[ASL22] Ro24 Preview: Siren's Call8[ASL22] Ro24 Preview: Summer's End9Serral wins HomeStory Cup 2915Serral wins Maestros of the Game 244ByuL, and the Limitations of Standard Play3
Community News
Stellar Fest TWO the Moon (Dec 16-20)8Weekly Cups (August 24-30): Patches' balance mod takes over2New 3v3 BGH Ladder (and more) on ShieldBattery!39Weekly Cups (August 17-23): Zerg dominate the week6Weekly Cups (August 10-16): SHIN doubles3
StarCraft 2
General
SC4ALL II: SC2 Player Announcement 6/8 - Maru Weekly Cups (August 10-16): SHIN doubles Weekly Cups (August 24-30): Patches' balance mod takes over How would you feel about frequent/monthly balance patches for SC2? Weekly Cups (August 17-23): Zerg dominate the week
Tourneys
Stellar Fest TWO the Moon (Dec 16-20) 2026 GSTL Announcement PIG STY FESTIVAL 8.0! (13 - 23 August) Sparkling Tuna Cup - Weekly Open Tournament IntoTheTV X SOOP SC2 League : Weekly & Monthly
Strategy
[G] Having the right mentality to improve
Custom Maps
Nexus Wars 2021 GUIDE [M] (2) Industrial Park
External Content
Mutation # 541 Binary Choice The PondCast: SC2 News & Results Mutation # 540 Dodge This Mutation # 539 Thunder Dome
Brood War
General
Which box art did your first copy of StarCraft 1 have? New 3v3 BGH Ladder (and more) on ShieldBattery! ASL22 General Discussion [Personal Project Share] Terran Defense v0.60 BW General Discussion
Tourneys
BSL LAN Party - Kraków 29-30 August - OPEN SIGNUPS [ASL22] Ro24 Group F [Megathread] Daily Proleagues Small VOD Thread 2.0
Strategy
Replay Review Process - What do you do? Game Theory for Starcraft Odyssey Mineral Stack Saturation Fighting Spirit mining rates
Other Games
General Games
Stratus: Battle for the sky now on steam Early acc General RTS Discussion Thread Nintendo Switch Thread Stormgate/Frost Giant Megathread Anyone here play Quakeworld back in the day?
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
[TL LoL EUW IHs] Teemo shall perish TSM pausing esports and CLG Dead
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Power Rank TL Mafia Community Thread NeO.D_StephenKing vs This Guy From 1 Million Dance
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine Canadian Politics Mega-thread European Politico-economics QA Mega-thread
Fan Clubs
MarineLorD Fan Club The Creator Fan Club The ShoWTimE Fan Club
Media & Entertainment
Movie Discussion! Anime Discussion Thread
Sports
Football (Soccer) Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023 NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Northern Ireland Global Starcraft
Blogs
Regacy Esports: The Bh…
regacyesports
Violent Games and Crime Rate…
TrAiDoS
LOCKPICKING NOOB
LUCKY_NOOB
Cathedral Of CS And NY pizza a…
FuDDx
Please support my new stand…
Peanutsc
Customize Sidebar...

Website Feedback

Closed Threads



Active: 4906 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 States3707 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 3h 45m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
ProTech140
EnDerr 6
StarCraft: Brood War
Hyuk 855
Shinee 162
Yoon 98
910 35
NaDa 24
ajuk12(nOOB) 10
League of Legends
JimRising 701
Counter-Strike
Coldzera 1236
Other Games
summit1g6081
ceh9498
XaKoH 413
Happy186
Livibee131
[ Show 13 non-featured ]
StarCraft 2
• Berry_CruncH377
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• iopq 7
• Light_VIP 7
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Rush1317
• Lourlo1224
Upcoming Events
Kung Fu Cup
3h 45m
RotterdaM Event
9h
Replay Cast
16h 45m
The PondCast
1d 2h
IntoTheTV X SOOP
2 days
CranKy Ducklings
3 days
Sparkling Tuna Cup
4 days
OSC
4 days
Shopify Rebellion Sundays
4 days
Mixu vs TBD
Spirit vs TBD
Clem vs TBD
Afreeca Starleague
5 days
Soma vs Shuttle
BeSt vs Rush
[ Show More ]
WardiTV Weekly
5 days
Afreeca Starleague
6 days
Leta vs ggaemo
Jaedong vs Queen
GSL
6 days
PiGosaur Cup
6 days
Liquipedia Results

Completed

KCM Special KOR vs CHN
PiG Sty Festival 8.0
Light Tournament 2026

Ongoing

KCM Race Survival 2026 Season 3
K-JUNGMAN
ASL Season 22
Super Anchor Qualifying S3
CSL 2026 AUTUMN (S22)
RSL Revival: Season 6
Calamity Invitational
Big Dog Cup 2026 Div 1
BLAST Open Fall 2026
Esports World Cup 2026
Esports World Cup 2026: LCQ
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026

Upcoming

Acropolis #5
Acropolis #5 - TRS
Escore Tournament S3: King of Kings
Blizzard Classic Cup 2026
Acropolis #5 - GSA
Acropolis #5 - GSB
Acropolis #5 - GSC
HSC XXX
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
BLAST Rivals Fall 2026
IEM Beijing 2026
Stake Ranked Episode 5
PGL Masters Bucharest 2026
1win Private Club #2
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
Logitech G Play Connect 2026
SL StarSeries Fall 2026
FISSURE Playground #3
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.