• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Printf and Equations

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
lowercase baba
Posts: 13081
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
 
I can't beleive you just said that. Now I need to calm down with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic