• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 14:31
CEST 20:31
KST 03:31
  • 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
[ASL19] Finals Recap: Standing Tall9HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Flash Announces Hiatus From ASL63Weekly Cups (June 23-29): Reynor in world title form?13FEL Cracov 2025 (July 27) - $8000 live event22Esports World Cup 2025 - Final Player Roster16Weekly Cups (June 16-22): Clem strikes back1
StarCraft 2
General
Program: SC2 / XSplit / OBS Scene Switcher The SCII GOAT: A statistical Evaluation Statistics for vetoed/disliked maps Weekly Cups (June 23-29): Reynor in world title form? PiG Sty Festival #5: Playoffs Preview + Groups Recap
Tourneys
FEL Cracov 2025 (July 27) - $8000 live event RSL: Revival, a new crowdfunded tournament series Sparkling Tuna Cup - Weekly Open Tournament WardiTV Mondays Korean Starcraft League Week 77
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma Mutation # 477 Slow and Steady
Brood War
General
Flash Announces Hiatus From ASL BW General Discussion Player “Jedi” cheat on CSL SC uni coach streams logging into betting site Practice Partners (Official)
Tourneys
The Casual Games of the Week Thread CSL Xiamen International Invitational [BSL20] Grand Finals - Sunday 20:00 CET [Megathread] Daily Proleagues
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread Nintendo Switch Thread What do you want from future RTS games? Beyond All Reason
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
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Summer Games Done Quick 2025! Trading/Investing Thread Things Aren’t Peaceful in Palestine
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
Formula 1 Discussion 2024 - 2025 Football Thread NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Blogs
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 585 users

The Big Programming Thread - Page 157

Forum Index > General Forum
Post a Reply
Prev 1 155 156 157 158 159 1031 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 States3696 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 1031 Next
Please log in or register to reply.
Live Events Refresh
BSL: ProLeague
18:00
Grand Finals - bo9
Dewalt vs Bonyth
ZZZero.O284
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 758
BRAT_OK 130
MindelVK 36
StarCraft: Brood War
Bisu 900
EffOrt 425
Mini 307
ZZZero.O 284
Soma 258
Hyuk 176
TY 114
ToSsGirL 69
Terrorterran 15
HiyA 13
[ Show more ]
LuMiX 5
Stormgate
BeoMulf171
NightEnD11
Dota 2
qojqva2993
League of Legends
Grubby2996
Dendi2110
Counter-Strike
fl0m1627
Super Smash Bros
Mew2King140
Chillindude43
Westballz26
Heroes of the Storm
Khaldor867
Liquid`Hasu520
Other Games
Gorgc3091
FrodaN2805
B2W.Neo730
mouzStarbuck297
KnowMe115
elazer88
Organizations
Other Games
gamesdonequick41245
EGCTV1698
StarCraft 2
angryscii 21
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 19 non-featured ]
StarCraft 2
• HeavenSC 30
• Adnapsc2 26
• maralekos13
• IndyKCrew
• sooper7s
• AfreecaTV YouTube
• Migwel
• intothetv
• LaughNgamezSOOP
• Kozan
StarCraft: Brood War
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 4274
• Ler159
League of Legends
• masondota2559
Other Games
• imaqtpie2047
• Shiphtur676
• WagamamaTV378
Upcoming Events
Wardi Open
16h 29m
Monday Night Weeklies
21h 29m
Replay Cast
1d 5h
Sparkling Tuna Cup
1d 15h
WardiTV European League
1d 21h
MaNa vs sebesdes
Mixu vs Fjant
ByuN vs HeRoMaRinE
ShoWTimE vs goblin
Gerald vs Babymarine
Krystianer vs YoungYakov
PiGosaur Monday
2 days
The PondCast
2 days
WardiTV European League
2 days
Jumy vs NightPhoenix
Percival vs Nicoract
ArT vs HiGhDrA
MaxPax vs Harstem
Scarlett vs Shameless
SKillous vs uThermal
Replay Cast
3 days
RSL Revival
3 days
ByuN vs SHIN
Clem vs Reynor
[ Show More ]
Replay Cast
4 days
RSL Revival
4 days
Classic vs Cure
FEL
4 days
RSL Revival
5 days
FEL
5 days
FEL
5 days
Sparkling Tuna Cup
6 days
RSL Revival
6 days
FEL
6 days
Liquipedia Results

Completed

BSL 2v2 Season 3
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL Season 20
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
CSL Xiamen Invitational
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
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
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.