Homework help

This is a discussion on Homework help within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by arsenalftw067 the program now shows how many times I rolled each number but no th It doesn't ...

  1. #16
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,638
    Quote Originally Posted by arsenalftw067 View Post
    the program now shows how many times I rolled each number but no th
    It doesn't show what now?

  2. #17
    Registered User
    Join Date
    Mar 2012
    Posts
    16
    Not the percentage of each rolled number

  3. #18
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,638
    I see. You use expressions like this:

    (num3/times_rolled)*100

    The major issue is that since both times_rolled and num3 (but numN in general applies to this) are integers, integer division takes place. If you want an answer other than zero, you need to cast one of the dividing terms to say, float, to yield percentages.

  4. #19
    Registered User
    Join Date
    Mar 2012
    Posts
    16
    So I would have to have the num1 num2 etc all in floats?

  5. #20
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,457
    No, it means you should do
    (static_cast<float>(num3)/times_rolled)*100
    Now num3 will be converted into a float in this calculation which means you will do a floating point division which will keep the decimals.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework Help
    By andrei1599 in forum C# Programming
    Replies: 1
    Last Post: 02-06-2011, 08:38 PM
  2. My homework
    By Bala in forum C++ Programming
    Replies: 5
    Last Post: 06-12-2010, 11:11 AM
  3. help about homework
    By agathery in forum C Programming
    Replies: 27
    Last Post: 05-19-2010, 09:17 PM
  4. homework
    By misplaced in forum C++ Programming
    Replies: 18
    Last Post: 10-04-2004, 06:56 AM
  5. I want homework!
    By Tynnhammar in forum C++ Programming
    Replies: 9
    Last Post: 09-29-2004, 02:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21