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



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

Source

READ ALSO:  Minecraft Mod Tutorials - Universal Electricity - Atomic Science #3 (Deutsch HD) | Video

37 Comments

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

    }

  2. 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

  3. 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)

  4. 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.

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

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

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

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

Comments are closed.