Thread: Trying to find the original value

  1. #1
    Registered User
    Join Date
    Sep 2017
    Posts
    93

    Trying to find the original value

    I know the title doesn't make a whole lot of sense and I'm going to be terrible at trying to explain it.

    I'm trying to write a program that finds the original value from a percentage down and the last known value.

    Example:
    Bitcoin was at $4420 which was down 4.9% from last month. I'm wanting my program to calculate what that number was.

    The way it's currently written, I'm aware that percents must be entered like "0.05" for 5%.

    Code:
    //
    //  main.c
    //  valuefinder
    //
    //  Created by Joshua Ernzen on 10/3/17.
    //  Copyright © 2017 Joshua Ernzen. All rights reserved.
    //
    // This program is suppose to find the starting value from a percent down.
    // Example: $4,420 is 4.9% down from last month. Find the original value
    
    #include <stdio.h>
    #include <stdint.h>
    
    int main() {
        double incnumber, usernumber, numberholder, finalnumber, percent;
        int8_t loop;
        loop = 1;
        
        printf("Please enter the value: ");
        scanf("%lf", &usernumber);
        printf("Please enter the percentage: ");
        scanf("%lf", &percent);
        
        incnumber = usernumber;
        
        while(loop == 1) {
            numberholder = incnumber * percent;
            finalnumber = numberholder + incnumber;
            
            if(finalnumber - numberholder != usernumber) {
                incnumber = incnumber + 0.01;
                printf("%lf\n", incnumber);
            }
            if(finalnumber - numberholder == usernumber)
                loop = 0;
        }
        
        printf("%lf is %lf of %lf\n", usernumber, percent, finalnumber);
        
        return 0;
    }
    Right now when it executes, it just takes let's say the value of 5% of 95 (4.75) and just adds it to 95. This happens when I attempt to find 95 is 5% down from last week, which should be 100.

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    So the output of the code should look like this?

    Code:
    Enter current value: 4420
    Enter percentage   : 4.9
    
    Original value: 4647.74
    You're better off figuring out how to solve this by hand first. This can be implemented with a simple equation.

  3. #3
    Registered User
    Join Date
    Sep 2017
    Posts
    93
    Yes, that's suppose to be the output.

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Have you attempted to solve a general case equation for this calculation?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 10-06-2017, 12:14 AM
  2. Original MMORPG
    By FiftyNine50 in forum Projects and Job Recruitment
    Replies: 13
    Last Post: 08-17-2007, 12:54 PM
  3. Original sin()
    By SMurf in forum C Programming
    Replies: 6
    Last Post: 02-22-2005, 02:48 AM
  4. original linux thread
    By caroundw5h in forum Linux Programming
    Replies: 3
    Last Post: 04-16-2004, 04:01 AM
  5. you need to come original!
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 09-24-2001, 09:47 PM

Tags for this Thread