Thread: Trying to find an original value of a percentage down to another value

1. Trying to find an original value of a percentage down to another 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.
//
// 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;

scanf("%lf", &usernumber);
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;
}
The way it currently works seems to ignore the "if" statements.

What it actually does is, let's say I enter 95 and down 5%. That would mean that 100 was the original value. The program just adds 4.75 to 95 which means it just added the value of 5% of 95 to 95. 2. 95 / (1.0 - 0.05) = 100 3. Why have you started a new thread for the same topic?  Popular pages Recent additions double, incnumber, increment, numberholder, numbers 