• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 05:25
CET 11:25
KST 19:25
  • 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
RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13
Community News
Weekly Cups (Nov 10-16): Reynor, Solar lead Zerg surge1[TLMC] Fall/Winter 2025 Ladder Map Rotation14Weekly Cups (Nov 3-9): Clem Conquers in Canada4SC: Evo Complete - Ranked Ladder OPEN ALPHA8StarCraft, SC2, HotS, WC3, Returning to Blizzcon!45
StarCraft 2
General
[TLMC] Fall/Winter 2025 Ladder Map Rotation RotterdaM "Serral is the GOAT, and it's not close" Weekly Cups (Nov 10-16): Reynor, Solar lead Zerg surge Mech is the composition that needs teleportation t RSL Season 3 - RO16 Groups C & D Preview
Tourneys
2025 RSL Offline Finals Dates + Ticket Sales! $5,000+ WardiTV 2025 Championship RSL Revival: Season 3 Sparkling Tuna Cup - Weekly Open Tournament Constellation Cup - Main Event - Stellar Fest
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 500 Fright night Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened
Brood War
General
FlaSh on: Biggest Problem With SnOw's Playstyle What happened to TvZ on Retro? BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review BW General Discussion
Tourneys
[BSL21] GosuLeague T1 Ro16 - Tue & Thu 22:00 CET [Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL21] RO32 Group D - Sunday 21:00 CET
Strategy
Current Meta How to stay on top of macro? PvZ map balance Simple Questions, Simple Answers
Other Games
General Games
Clair Obscur - Expedition 33 Stormgate/Frost Giant Megathread Beyond All Reason Should offensive tower rushing be viable in RTS games? Path of Exile
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
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread The Games Industry And ATVI Things Aren’t Peaceful in Palestine About SC2SEA.COM
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Dyadica Gospel – a Pulp No…
Hildegard
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Reality "theory" prov…
perfectspheres
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2064 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 1h 36m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
ProTech126
SortOf 116
Livibee 109
StarCraft: Brood War
Calm 4720
GuemChi 1878
Stork 507
BeSt 473
Larva 422
Pusan 304
EffOrt 252
Killer 206
Leta 200
Zeus 176
[ Show more ]
Dewaltoss 75
ToSsGirL 65
ZerO 40
Rush 37
Mind 29
yabsab 28
Barracks 25
hero 24
Movie 23
Noble 13
Terrorterran 7
Dota 2
XaKoH 494
XcaliburYe64
League of Legends
JimRising 456
Reynor117
Counter-Strike
olofmeister1361
shoxiejesuss603
Other Games
summit1g16066
ceh9499
Happy255
Fuzer 231
crisheroes109
Pyrionflax89
Trikslyr38
NeuroSwarm36
ZerO(Twitch)2
Organizations
Dota 2
PGL Dota 2 - Main Stream8475
PGL Dota 2 - Secondary Stream1685
Other Games
gamesdonequick597
BasetradeTV33
StarCraft: Brood War
lovetv 10
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• Berry_CruncH161
• LUISG 24
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Stunt720
Upcoming Events
WardiTV Korean Royale
1h 36m
BSL: GosuLeague
10h 36m
PiGosaur Cup
14h 36m
The PondCast
23h 36m
Replay Cast
1d 12h
RSL Revival
1d 23h
herO vs Zoun
Classic vs Reynor
Maru vs SHIN
MaxPax vs TriGGeR
BSL: GosuLeague
2 days
RSL Revival
2 days
WardiTV Korean Royale
3 days
RSL Revival
3 days
[ Show More ]
WardiTV Korean Royale
4 days
IPSL
4 days
Julia vs Artosis
JDConan vs DragOn
RSL Revival
4 days
Wardi Open
5 days
IPSL
5 days
StRyKeR vs OldBoy
Sziky vs Tarson
Replay Cast
5 days
Replay Cast
6 days
Liquipedia Results

Completed

Proleague 2025-11-14
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
CSCL: Masked Kings S3
SLON Tour Season 2
RSL Revival: Season 3
META Madness #9
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
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.