Help with a logic

Discussion in 'C' started by baskarvj, Aug 2, 2010.

  1. baskarvj

    baskarvj New Member

    Joined:
    May 17, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I need to write a C++ program to do the following things, and i have displayed my attempted code. Please let me know if there is more effective way to do this.

    - I need to calculate the % based on the input values (run-time)
    - The percentage value will keep on increasing based on the input values.

    For eg

    If the input is 30, then it after completing the 1st operation it should display 1 % .... and after completing 2nd operation it should display 2 % and so on, and when it completes 30th operation it will display 100 %.

    Note: the input values is a random number.


    My logic

    Case 1: If the input is 30

    1/30 = 0.03 and multiply the result by 100 then the value is 3 %
    .........
    30/30 = 1 result will be 100 %

    It is ok to have the % is some increasing order, rather than more presisely with 1%,2% etc.

    But problem is my logic will not work for this case

    Case 2: If the input is for eg 300

    then 1/300 = 0.033 and multiply the result by 100 then the value is 0.33, in this case i should multiply by 1000 instead of 100 to get the round value.

    Any idea on how to deal with this.

    Thanks in advance.
     
  2. virxen

    virxen Active Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    28
    try to explain better what you want to do
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Where?

    I also don't understand the problem here:
    Why do you think you need to multiply the result by 1000? Why do you think that .033 * 100 = .33? Did you try that on a calculator? If you multiply by 1000 instead of 100, you won't get 1% for 1/300, and the progress bar will finish (a) at 1000%, or (b) when you're 1/10th of the way through the task.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice