# Buckys C++ Programming Tutorials – 23 – Making a Stock Market Simulator! | Video

GitHub – https://github.com/buckyroberts
reddit – https://www.reddit.com/r/thenewboston/
Support – https://www.patreon.com/thenewboston
thenewboston – https://thenewboston.com/
Proudly WWW.PONIREVO.COM

Source

READ ALSO:  Special coronavirus precautions taken to protect elderly | News

1. i don't like the stock market, mostly because formula doesn't make any fucking sense?

2. No need for " float r = .01 "
just have it in the formula like this " a = p * pow(1.01, day); "

3. or something like this:

#include <iostream>

#include <cmath>

using namespace std;

int main()

{

float p = 10000;

float r = 0.01;

for (int day=1; day<=20; day++){

p *= (1+r);

cout << day << " ————- " << p << endl;

}

return 0;

}

4. I cant understand why we have to put the rate as 0.01 ?

5. Are float and double the same thing? Just making sure.

6. There is no need to use a formula etc . Add money * r to money and increment day .So :
money += money *r ;
day++ ;
Because , during 20 days , our money will be incremented by money *r . And we will add this 20 times

7. just to be clear warren makes like 19% a year on his investments and not 3 percent per day

8. By the way if you assign a float like: float x = 2.34; This is technically a double(8 bytes of data) even tho you wrote float!
if you want to create it as float (4 bytes of data) you have to do: float x = 2.34f; By adding an ' f ' to the end!

EDIT: If you dont belive me try it yourself. Enable InelliSense if its not enabled and hover over the variable number ( float x = .02; )
………………………………………………………………………………………………………………………………………………………………..Hover over this ^^ and you will see it says (double)(0.02)

9. Where are the rest of the decimals? Why are the numbers rounded to 1 decimal?

10. Any body having trouble with pow get a error make sure you put in #include <cmath> which is at the top hope this clear some confusion

11. I am confused why you used pow? Isn't it easier to just use your p and r variables and just make p = p + (p * r); ?? Sorry, I am very new to programming….but pow is confusing me in this example.

12. #include <iostream>
#include<cmath>

using namespace std;

int main()
{
int a=5;
int b=2;
int y=pow(a,b);
cout<<y<< endl;

return 0;
}
why my result is 24 instead of 25. thank you

13. im an idiot i did this. at least i did it from everything i learned from bucky

#include <iostream>

using namespace std;

int main()
{

int money = 10000;
int interest = 0;

for(int days = 1; days < 31; days++){

interest = (money * days) / 100;

}

cout << interest << endl;
return 0;
}

14. Another Way:

float invest = 10000;

for (int day =1 ; day<=20 ; day++)

{

invest += 0.01* invest ;

}

cout << invest ;

15. 3% a day… lol…

16. the thought of shoving everything into the main method kind of creeps me out . its good if you do stuff object oriented ( OO) way from the beginning. Heres what I did :

#include <iostream>
#include <cmath>

using namespace std;

class MyClass{
public:
double cal(float p,float r,int days){
double sum = 0;
for(int i=1 ; i<=days;i++){
sum += p*pow(1+r,i);
}
return sum;
}

};
int main(){
float a;
float b;
MyClass ob;
a = ob.cal(1000,0.2,20) ;
b = ob.cal (100,0.2,10);
cout << a <<endl;
cout << b<< endl;
return 0 ;
}

17. can we use while loop instead?

18. i felt stupid looking at that algorithm and not understanding it xD

19. That's if the retarded capitalists don't crash it and you loose the 10000 dollars the first day.

20. i wonder what is this mean ?
error: range-based 'for' loops are not allowed in C++98 mode

21. that's ultimate weird formula i'd rather use this
p=p+(p*0.01) easier to me

22. 3% a year is good? you can make 10% per year easily buying an S&P500 index fund and the only way you'd loose money is if the stock market crashed.

23. why didn't he type all the variables on the same line with one float?

24. Haven't watch the full video yet – I stopped when you said we needed to include "cmath" in

I tried to create my own without cmath, and had a very successful result. What's the reason for including cmath, as oppossed to just using iostream?

Here's my code:

#include <iostream>
using namespace std;

float money, interest;
int x;

int main()
{
cout << "What is your starting amount?" << endl;
cin >> money;
cout << endl << "Your starting amount is \$" << money << endl;

for (x=1; x<31; ++x)
{
interest = money / 10;
money = interest + money;
cout << "Your interest on Day " << x << " is \$" << interest << "." << endl;
cout << "Day " << x << " total = " << money << endl << endl;
}

cout << "Your final total, after 30 days, at 10% interest per day, is \$" << money << endl << "See the above log for a more detailed breakdown." << endl;
return 0;
}

25. This stock market simulator is more like a way to calculate compound interest

26. But!
Someone has to make/program those trade buttons, that is us, and we make much more money on that

27. it's to the power of years not days

28. I thought it would be some kind of advanced c++ tutorial implementing complex systems etc…

29. You'd have to be a wizard to make a 1% return a day. The average annual return is about 10%.