I'm stuck on a part in my program. Some numbers are adding up properly, others aren't. I assume the problem is that I'm using integers instead of doubles, however, how would you format the following in C?
How to describe it, it's like a chain. I have to take a percentage of an initial value and add it to the next number. Then take a percentage of the next number and add that to the next number. The numbers get pretty big, and the percentages vary, 5%, 10%, 30%. For the most part, everything works out nice and well, but theres a few numbers that are off by 1, either +1 or -1. If I try to add something like +0.5 after the statement it throws off other numbers. So, logically it seems reasonable I'd need to switch from ints to doubles, but that confuses me as to how the output will look. The output cannot be in decimal form. Can you take a double number and print it out as an integer would look?
Heres how the current int output looks:
The 4 space format is necessary. Is there a way to take a type double number, say, 5.32 and make it appear on the output as just "5" yet still be formatted with the 4 spaces?