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;
}
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.