Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printf and Equations

 
Elle de Vasquez
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Help please!

------------------------------------------------
Supreme Commander: Forged Alliance

Information SylverMoon74 GreenChaos86
------------------------------------------------

Games Played 20 20
Games Won 7 13
Avg. Games Won , 0.35 0.65
------------------------------------------------

Q1 - Avg. Games Won - has a comma (,) after it...why?
Q2 - I want to use the equation for avgw1 and avgw2 (the part that's commented out), but it gives me 0.00 as answers for both columns. Did I do the math wrong? the formatting?

Help!

Thanks much!
Sylver
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1 : Because you're printing one ! Look closely.
 
Elle de Vasquez
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh good god...I just saw it now that you've pointed it out >.< Thanks!

Anything for q2?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q2 : you'll have to make one of the two operands a double, otherwise the result will be an int (check this link). Try to cast one of the operands.
 
Elle de Vasquez
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh! Got it, thank you VERY much!!! <3

------------------------------------------------
Supreme Commander: Forged Alliance

Information SylverMoon74 GreenChaos86
------------------------------------------------

Games Played 20 20
Games Won 7 13
Avg. Games Won 0.35 0.65
------------------------------------------------
Got it to work making games won a double instead of just an int
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12098
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my opinion, it should be an int. You can't win part of a game (unless you count a tie as a half), so logically it makes sense for it to be an int.

What I would do is cast it during the computation:

double avgw1 = (float) gw1/gp1;
double avgw2 = (float) gw2/gp2;
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic