• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 16:16
CET 21:16
KST 05:16
  • 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
Team Liquid Map Contest #22 - Presented by Monster Energy5ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13
Community News
Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool30Weekly Cups (March 9-15): herO, Clem, ByuN win42026 KungFu Cup Announcement6BGE Stara Zagora 2026 cancelled12Blizzard Classic Cup - Tastosis announced as captains18
StarCraft 2
General
Weekly Cups (March 9-15): herO, Clem, ByuN win Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Team Liquid Map Contest #22 - Presented by Monster Energy Serral: 24’ EWC form was hurt by military service Weekly Cups (August 25-31): Clem's Last Straw?
Tourneys
RSL Season 4 announced for March-April Sparkling Tuna Cup - Weekly Open Tournament WardiTV Team League Season 10 KSL Week 87 [GSL CK] #2: Team Classic vs. Team Solar
Strategy
Custom Maps
Publishing has been re-enabled! [Feb 24th 2026] Map Editor closed ?
External Content
The PondCast: SC2 News & Results Mutation # 517 Distant Threat Mutation # 516 Specter of Death Mutation # 515 Together Forever
Brood War
General
Buy weed dexies in Australia (WhatsApp 0480852135) BGH Auto Balance -> http://bghmmr.eu/ ASL21 General Discussion Gypsy to Korea JaeDong's form before ASL
Tourneys
[BSL22] Open Qualifiers & Ladder Tours [Megathread] Daily Proleagues Small VOD Thread 2.0 IPSL Spring 2026 is here!
Strategy
Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2 Fighting Spirit mining rates
Other Games
General Games
General RTS Discussion Thread Nintendo Switch Thread Path of Exile Stormgate/Frost Giant Megathread Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion 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
Five o'clock TL Mafia Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia TL Mafia Community Thread
Community
General
Things Aren’t Peaceful in Palestine US Politics Mega-thread Canadian Politics Mega-thread Russo-Ukrainian War Thread Mexico's Drug War
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Movie Discussion! [Req][Books] Good Fantasy/SciFi books [Manga] One Piece
Sports
Formula 1 Discussion 2024 - 2026 Football Thread Tokyo Olympics 2021 Thread General nutrition recommendations Cricket [SPORT]
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
The Automated Ban List
Blogs
Funny Nicknames
LUCKY_NOOB
Money Laundering In Video Ga…
TrAiDoS
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2139 users

The Big Programming Thread - Page 254

Forum Index > General Forum
Post a Reply
Prev 1 252 253 254 255 256 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.
zf
Profile Joined April 2011
231 Posts
February 23 2013 19:41 GMT
#5061
On February 23 2013 04:07 ranshaked wrote:

if(currentFace == "Ace");{
//int sameCardsAce=0;
sameCardsAce++;
if(sameCardsAce==2)
System.out.println("You have a pair");
}


Why are there semicolons after the conditions?
Soan
Profile Blog Joined August 2010
New Zealand194 Posts
February 23 2013 21:29 GMT
#5062
On February 23 2013 15:27 phar wrote:
You are exactly right, performance arguments like this are always pointless.


Yeah, I'm doing a games programming course, and one of the things they try to drill into us is to forget about performance. Make something that works first, and then worry about performance.
phar
Profile Joined August 2011
United States1080 Posts
February 23 2013 21:31 GMT
#5063
On February 24 2013 04:41 zf wrote:
Show nested quote +
On February 23 2013 04:07 ranshaked wrote:

if(currentFace == "Ace");{
//int sameCardsAce=0;
sameCardsAce++;
if(sameCardsAce==2)
System.out.println("You have a pair");
}


Why are there semicolons after the conditions?

Because it's wrong. Don't follow that code's syntax exactly.
Who after all is today speaking about the destruction of the Armenians?
Arnstein
Profile Blog Joined May 2010
Norway3381 Posts
Last Edited: 2013-02-24 13:53:18
February 24 2013 13:35 GMT
#5064
+ Show Spoiler +


#include "Oving 5 del 1.h"
#include <iostream>

using namespace std;


class Matrix2x2
{
private:
double matrix[1][1];
public:
Matrix2x2();
void setValue(int x, int y, double value);
double getValue(int x, int y);
void printMatrix();

};



int main()
{
Matrix2x2 a;
a.printMatrix();
a.setValue(0.0,0.0,1.0);
a.printMatrix();

}

Matrix2x2::Matrix2x2()
{
matrix.setValue(0, 0, 1.0);
matrix.setValue(0, 1, 0.0);
matrix.setValue(1, 0, 0.0);
matrix.setValue(0, 1, 1.0);
}


void Matrix2x2::setValue(double x, double y, double value)
{
matrix[x][y] = value;
}

double Matrix2x2::getValue(double x, double y)
{
return matrix[x][y];
}



void Matrix2x2::printMatrix()
{
for (int i = 0;i<2;i++)
{
for (int s = 0;s<2;s++)
{
cout << matrix[i][s] << " ";

}
cout << endl;
}
}







I get really many errors on this one. Why doesn't this work?
rsol in response to the dragoon voice being heard in SCII: dragoon ai reaches new lows: wanders into wrong game
myzael
Profile Blog Joined November 2008
Poland605 Posts
February 24 2013 13:36 GMT
#5065
That reminds me when I wasted half a day trying to find why the following code wasn't working as desired:

while(true);{
//do something
}


Good times :D
Marradron
Profile Blog Joined January 2009
Netherlands1586 Posts
Last Edited: 2013-02-24 13:38:49
February 24 2013 13:38 GMT
#5066
arent the functions supposed to be inside the class ?

Furthermore, reading the errors should give you an idea where it goes wrong.
Arnstein
Profile Blog Joined May 2010
Norway3381 Posts
February 24 2013 13:46 GMT
#5067
On February 24 2013 22:38 Marradron wrote:
arent the functions supposed to be inside the class ?

Furthermore, reading the errors should give you an idea where it goes wrong.


Isn't it easier to read when they are outside? (as long as the functions are longer than one line)
All the problems has to do with the constructor! As soon as I remove it, there's no problem. I want to set the default values of the matrix declared in private, how should I do this?

rsol in response to the dragoon voice being heard in SCII: dragoon ai reaches new lows: wanders into wrong game
Marradron
Profile Blog Joined January 2009
Netherlands1586 Posts
February 24 2013 13:54 GMT
#5068
On February 24 2013 22:46 Arnstein wrote:
Show nested quote +
On February 24 2013 22:38 Marradron wrote:
arent the functions supposed to be inside the class ?

Furthermore, reading the errors should give you an idea where it goes wrong.


Isn't it easier to read when they are outside? (as long as the functions are longer than one line)
All the problems has to do with the constructor! As soon as I remove it, there's no problem. I want to set the default values of the matrix declared in private, how should I do this?



I wasnt sure that was allowed. Haven't programmed in c++ in a while.
AKnopf
Profile Blog Joined March 2011
Germany259 Posts
Last Edited: 2013-02-24 14:45:49
February 24 2013 14:45 GMT
#5069
I dont know C++, but what is the scope of matrix in the following function?

void Matrix2x2::setValue(double x, double y, double value)
{
matrix[x][y] = value;
}


Should it not be this[x][y]= value; ?
The world - its a funny place
SgtCoDFish
Profile Blog Joined July 2010
United Kingdom1520 Posts
Last Edited: 2013-02-24 15:00:57
February 24 2013 14:56 GMT
#5070
On February 24 2013 23:45 AKnopf wrote:
I dont know C++, but what is the scope of matrix in the following function?

void Matrix2x2::setValue(double x, double y, double value)
{
matrix[x][y] = value;
}


Should it not be this[x][y]= value; ?


Without trying to sound aggressive: While your attempts to help are appreciated, they're useless if you don't know C++.

matrix[x][y] refers to the member variable "matrix". "this" is a special pointer to the calling object. That part is likely correct Saying matrix[x][y] in a member function defaults to this->matrix[x][y]

@ the guy who posted the question: If you want help, it usually is useful to post error messages. If there are loads, pick ones that seem common.

Also, you're using doubles to index a matrix in the declarations of the getter/setter. That makes no sense, matrix indices are integers. As such, your get and set functions should take int x, int y (and double for the value, that's correct). You have it right in the declarations.

And you're fine to declare functions outside the class. It's not uncommon to have the class in a header file and the function declarations in a separate .cpp file.

Also, in your constructor you should be calling either this->setValue(...) or just setValue(...) (which will call it on "this" for you). This is why it's failing in the constructor and is probably the source of all your problems.
moe475
Profile Joined June 2011
Sweden8 Posts
Last Edited: 2013-02-24 15:08:34
February 24 2013 15:03 GMT
#5071
On February 24 2013 23:56 SgtCoDFish wrote:
Show nested quote +
On February 24 2013 23:45 AKnopf wrote:
I dont know C++, but what is the scope of matrix in the following function?

void Matrix2x2::setValue(double x, double y, double value)
{
matrix[x][y] = value;
}


Should it not be this[x][y]= value; ?


Without trying to sound aggressive: You have no idea what you're talking about, and while your attempts to help are appreciated, they're useless if you don't know C++.

matrix[x][y] refers to the member variable "matrix". "this" is a special pointer to the calling object. That part is likely correct.

@ the guy who posted the question: If you want help, it usually is useful to post error messages. If there are loads, pick ones that seem common.

Also, you're using doubles to index a matrix. That makes no sense, matrix indices are integers. As such, your get and set functions should take int x, int y (and double for the value, that's correct)

And you're fine to declare functions outside the class. It's not uncommon to have the class in a header file and the function declarations in a separate .cpp file.

Also, in your constructor you should be calling either this->setValue(...) or just setValue(...) (which will call it on "this" for you). This is why it's failing in the constructor.


Very much agreed.
OP's problem seems to be in the constructor: He's calling setValue incorrectly.

+ Show Spoiler +
Line 29: matrix.setValue(0, 0, 1.0);


This should instead just be setValue(0, 0, 1.0); (as an object of type double[][] doesn't have a setValue method). That, and as you pointed out, changing the indices x and y to int in the type signature of getValue and setValue will make the code compile as far as I can tell.

Edit: clarified the fix to the code a bit
Arnstein
Profile Blog Joined May 2010
Norway3381 Posts
Last Edited: 2013-02-24 15:08:41
February 24 2013 15:04 GMT
#5072
Thanks! I will check this out. I DID change the double before you told me to, because I realized how stupid it was. Value is still double though.

Edit: That fixed it! Thanks guys, you are awesome! Now I have to deal with a whole crock of shit with operator overloading I really love to learn programming, but the amount of work the university requires, it really makes it a bit less fun, and more exhausting.
rsol in response to the dragoon voice being heard in SCII: dragoon ai reaches new lows: wanders into wrong game
waxypants
Profile Blog Joined September 2009
United States479 Posts
February 24 2013 15:32 GMT
#5073
Your definition of matrix should be double matrix[2][2];
moe475
Profile Joined June 2011
Sweden8 Posts
Last Edited: 2013-02-24 15:44:22
February 24 2013 15:34 GMT
#5074
On February 25 2013 00:32 waxypants wrote:
Your definition of matrix should be double matrix[2][2];

True, didn't even notice that because the program still happens to work (no bounds checking)... If this was more complicated chances are some other variable would be overwritten and you'd notice some strange bugs.
Edit #10: It did actually mess up indexing before, so the "wrong" array was printed.
Arnstein
Profile Blog Joined May 2010
Norway3381 Posts
February 24 2013 16:01 GMT
#5075
Is this true? I thought indexing started at number 0? So by creating [1][1] you get index 0 and index 1; 2 indexes?

Also, I seem to have misunderstood operator overloading syntax.

This is added to the previously seen code:
+ Show Spoiler +


const Matrix2x2 operator +(Matrix2x2& matrise1, Matrix2x2& matrise2);

const Matrix2x2 operator +(Matrix2x2& matrise1, Matrix2x2& matrise2)
{
double matrise[1][1];
matrise[0][0] = matrise1.getValue(0,0) + matrise2.getValue(0,0);
matrise[0][1] = matrise1.getValue(0,1) + matrise2.getValue(0,1);
matrise[1][0] = matrise1.getValue(1,0) + matrise2.getValue(1,0);
matrise[1][1] = matrise1.getValue(1,1) + matrise2.getValue(1,1);

}


This doesn't give any compiler errors, but it does give a warning since I don't have a return on the +operator.

Also, when I test it by making two matrices, a and b, then c = a+b;, I get this:

+ Show Spoiler +

Program received signal: “EXC_BAD_INSTRUCTION”.
sharedlibrary apply-load-rules all
warning: Unable to restore previously selected frame.
warning: Unable to restore previously selected frame.
warning: Unable to restore previously selected frame.
warning: Unable to restore previously selected frame.
(gdb)
rsol in response to the dragoon voice being heard in SCII: dragoon ai reaches new lows: wanders into wrong game
iaretehnoob
Profile Joined June 2004
Sweden741 Posts
February 24 2013 16:15 GMT
#5076
On February 25 2013 01:01 Arnstein wrote:
Is this true? I thought indexing started at number 0? So by creating [1][1] you get index 0 and index 1; 2 indexes?

Indexing starts at 0, but an array of size 1 still only has 1 (valid) index.
nakam
Profile Joined April 2010
Sweden245 Posts
Last Edited: 2013-02-24 16:50:59
February 24 2013 16:50 GMT
#5077
[MySQL]
Lets say I have the following table

id datetime playerid score
1 2013-02-15 19:15 1 10
1 2013-02-15 19:15 2 8
2 2013-02-16 19:15 2 5
3 2013-02-17 19:15 1 2
4 2013-02-20 19:15 2 1
5 2013-02-22 19:15 2 1

I now want the sum of the score for each player at that date so that the result becomes:

datetime playerid sumAtTime
2013-02-15 19:15 1 10
2013-02-15 19:15 2 8
2013-02-16 19:15 1 10
2013-02-16 19:15 2 13
2013-02-17 19:15 1 12
2013-02-17 19:15 2 13
2013-02-20 19:15 1 12
2013-02-20 19:15 2 14
2013-02-22 19:15 1 12
2013-02-22 19:15 2 15


It's almost like a SUM(score) and GROUP BY playerid, datetime.

How do I achieve this in MySQL? I know it is possible and very easy if I process this in php and I know how to do that, it's just that I'd like to do it with SQL if possible.
TL Local Timezone Script - http://www.teamliquid.net/forum/viewmessage.php?topic_id=277156
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2013-02-24 17:16:41
February 24 2013 17:07 GMT
#5078
[C language]

I have a rather simple presentation problem.

My output is like this:

number(space)number(space)
number(space)number(space)
number(space)number(space)

However, an online check program wants output without the 2nd space:
number(space)number
number(space)number
number(space)number

The variable answer is not unique. In other words, it is the only variable used for printing a value. Any suggestions?

Let me know if you need more info.

Sample code:

for (int x = 1; x < END; x++) {
for (int z = 0; z < x; z++) {
answer += var1 + var2;
printf("%d ", answer);
}
printf("\n");
}
phar
Profile Joined August 2011
United States1080 Posts
Last Edited: 2013-02-24 17:12:44
February 24 2013 17:10 GMT
#5079
On February 25 2013 01:50 nakam wrote:
[MySQL]
Lets say I have the following table
+ Show Spoiler +

id datetime playerid score
1 2013-02-15 19:15 1 10
1 2013-02-15 19:15 2 8
2 2013-02-16 19:15 2 5
3 2013-02-17 19:15 1 2
4 2013-02-20 19:15 2 1
5 2013-02-22 19:15 2 1

I now want the sum of the score for each player at that date so that the result becomes:

datetime playerid sumAtTime
2013-02-15 19:15 1 10
2013-02-15 19:15 2 8
2013-02-16 19:15 1 10
2013-02-16 19:15 2 13
2013-02-17 19:15 1 12
2013-02-17 19:15 2 13
2013-02-20 19:15 1 12
2013-02-20 19:15 2 14
2013-02-22 19:15 1 12
2013-02-22 19:15 2 15


It's almost like a SUM(score) and GROUP BY playerid, datetime.

How do I achieve this in MySQL? I know it is possible and very easy if I process this in php and I know how to do that, it's just that I'd like to do it with SQL if possible.

Take this with a grain of salt because my sql knowledge sucks, but I think you have it basically correct already

SELECT datetime,playerid,SUM(score) FROM TableTable GROUP BY datetime, playerid

I think you're right: http://beginner-sql-tutorial.com/sql-group-by-clause.htm

But again, I have literally never written and executed a line of SQL in my entire life, so...
Who after all is today speaking about the destruction of the Armenians?
Kambing
Profile Joined May 2010
United States1176 Posts
February 24 2013 17:18 GMT
#5080
On February 25 2013 02:07 darkness wrote:
I have a rather simple presentation problem.

My output is like this:

number(space)number(space)
number(space)number(space)
number(space)number(space)

However, an online check program wants output in without the 2nd space:
number(space)number
number(space)number
number(space)number

The variable is not unique. Any suggestions?

Let me know if you need more info.


Assuming that you are generating this sequence in a loop, this is an example of a fencepost loop. Your for-loop likely looks like this:


For each number n:
print n + " "


This generates the former sequence rather than the latter sequence. You can think of the for-loop as a stamp that repeatedly generates "number(space)". The trick is to recognize that this stamp cannot possibly generate the form on its own because of the special case at the end which has no space.

Your only recourse is to factor this special case out of loop:


For each number n except the last:
print n + " "
print the last number


This is called a fencepost loop because the problem is analogous to laying down fenceposts and wire.


|--|--|--|


There is one extra fencepost (n+1 overall) that you must account for when using n pieces of wire. The code ends up being easier to read if, rather than special casing the last post, you special case the first post and change the pattern accordingly:


print the first number
For each number n starting from the second:
print " " + n
Prev 1 252 253 254 255 256 1032 Next
Please log in or register to reply.
Live Events Refresh
BSL
20:00
S22 - Ladder Tour #2
LiquipediaDiscussion
LAN Event
16:30
StarCraft Madness
Airneanach148
Liquipedia
PSISTORM Gaming Misc
15:55
FSL semifinals: PTB vs ASH
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
elazer 275
JuggernautJason88
Nathanias 59
UpATreeSC 54
Ketroc 44
Vindicta 41
CosmosSc2 39
PattyMac 6
StarCraft: Brood War
EffOrt 576
Horang2 483
Shuttle 244
ggaemo 157
hero 103
Dewaltoss 83
Free 77
ZZZero.O 40
Hm[arnc] 25
ivOry 10
[ Show more ]
SilentControl 8
Dota 2
monkeys_forever283
LuMiX1
Counter-Strike
fl0m5791
shoxiejesuss406
Heroes of the Storm
Khaldor608
Liquid`Hasu401
Trikslyr79
MindelVK12
Other Games
Grubby3069
FrodaN2355
JimRising 485
byalli463
ToD132
Hui .73
Organizations
Other Games
gamesdonequick884
Dota 2
PGL Dota 2 - Main Stream116
StarCraft 2
angryscii 23
Other Games
BasetradeTV6
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 22 non-featured ]
StarCraft 2
• printf 30
• Adnapsc2 28
• LUISG 10
• Reevou 7
• Kozan
• LaughNgamezSOOP
• IndyKCrew
• intothetv
• Migwel
• AfreecaTV YouTube
• sooper7s
StarCraft: Brood War
• 80smullet 15
• Azhi_Dahaki7
• Michael_bg 6
• Pr0nogo 2
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota21124
• WagamamaTV1025
Other Games
• imaqtpie1118
• Shiphtur264
Upcoming Events
RSL Revival
13h 44m
herO vs MaxPax
Rogue vs TriGGeR
BSL
23h 44m
Replay Cast
1d 3h
Replay Cast
1d 12h
Afreeca Starleague
1d 13h
Sharp vs Scan
Rain vs Mong
Wardi Open
1d 15h
Monday Night Weeklies
1d 20h
Sparkling Tuna Cup
2 days
Afreeca Starleague
2 days
Soulkey vs Ample
JyJ vs sSak
Replay Cast
3 days
[ Show More ]
Afreeca Starleague
3 days
hero vs YSC
Larva vs Shine
Kung Fu Cup
3 days
Replay Cast
4 days
KCM Race Survival
4 days
The PondCast
4 days
WardiTV Team League
4 days
Replay Cast
5 days
WardiTV Team League
5 days
RSL Revival
6 days
Cure vs Zoun
WardiTV Team League
6 days
BSL
6 days
Liquipedia Results

Completed

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

Ongoing

KCM Race Survival 2026 Season 1
Jeongseon Sooper Cup
BSL Season 22
CSL Elite League 2026
RSL Revival: Season 4
Nations Cup 2026
NationLESS Cup
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual

Upcoming

ASL Season 21
Acropolis #4 - TS6
2026 Changsha Offline CUP
CSL 2026 SPRING (S20)
CSL Season 20: Qualifier 1
Acropolis #4
IPSL Spring 2026
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
IEM Cologne Major 2026
Stake Ranked Episode 2
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
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.