Facebook – https://www.facebook.com/TheNewBoston-464114846956315/
GitHub – https://github.com/buckyroberts
Google+ – https://plus.google.com/+BuckyRoberts
LinkedIn – https://www.linkedin.com/in/buckyroberts
reddit – https://www.reddit.com/r/thenewboston/
Support – https://www.patreon.com/thenewboston
thenewboston – https://thenewboston.com/
Twitter – https://twitter.com/bucky_roberts
Proudly WWW.PONIREVO.COM
Comments are closed.
6:07 hehe, you got that right
i don't like the stock market, mostly because formula doesn't make any fucking sense?
got it nice
No need for " float r = .01 "
just have it in the formula like this " a = p * pow(1.01, day); "
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;
}
I cant understand why we have to put the rate as 0.01 ?
Are float and double the same thing? Just making sure.
Stonks
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
just to be clear warren makes like 19% a year on his investments and not 3 percent per day
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)
Where are the rest of the decimals? Why are the numbers rounded to 1 decimal?
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
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.
#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
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;
}
hallow teacher Bucky u just added #include<cmath> but no explanation ?
$10000 LYING AROUND?!
Another Way:
float invest = 10000;
for (int day =1 ; day<=20 ; day++)
{
invest += 0.01* invest ;
}
cout << invest ;
3% a day… lol…
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 ;
}
U definetly made me google it
can we use while loop instead?
i felt stupid looking at that algorithm and not understanding it xD
That's if the retarded capitalists don't crash it and you loose the 10000 dollars the first day.
i wonder what is this mean ?
error: range-based 'for' loops are not allowed in C++98 mode
that's ultimate weird formula i'd rather use this
p=p+(p*0.01) easier to me
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.
why didn't he type all the variables on the same line with one float?
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;
}
You are the best teacher i have ever had. 😀
This stock market simulator is more like a way to calculate compound interest
But!
Someone has to make/program those trade buttons, that is us, and we make much more money on that
it's to the power of years not days
usually why/when do we use <cmath> ?
I thought it would be some kind of advanced c++ tutorial implementing complex systems etc…
You'd have to be a wizard to make a 1% return a day. The average annual return is about 10%.