Calculate total value along sequence based on fix percentage and sequence

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Calculate total value along sequence based on fix percentage and sequence



So I know how to do this using a function on any given programming language but I wonder how to do it with a formula. This is to calculate the price of a item in a game. The item cost initially 200 but once the user buys it, its price gets incremented a 20% so now cost 240 and it will cost 288 the very next time as it is a 20% increment from the last price. What if I want to calculate the price based on the sequence, lets say the item is on level 12 (has been bought or upgraded 11 times), what is the formula to calculate the price without using a loop (storing the previous value) but based only on the current level (12), the base price (200) and the fix percentage (20%)?




1 Answer
1


const price = (1+percent)**(level-1) * initialPrice



Basic compound interest formula :-)



(** is the power operator)


**






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived