baavgai's Profile User Rating: *****

Reputation: 6200 Overlord
Group:
Mentors
Active Posts:
13,343 (4.73 per day)
Joined:
16-October 07
Profile Views:
133,974
Last Active:
User is offline Today, 12:40 PM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Linux
Favorite Browser:
FireFox
Favorite Processor:
Who Cares
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
725
Expert In:
C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

Latest Visitors

Icon   baavgai has not set their status

Posts I've Made

  1. In Topic: C++ book for C programmers

    Posted 4 Jul 2015

    View PostCrazySynthax, on 03 July 2015 - 04:21 PM, said:

    I find it boring since I already know the basics of C.


    Um, tough. ;)

    C and C++ are very different languages. You are much better off going in with that in mind and learning C++ from chapter one. If you think "I know all this already" you are pretty much setting yourself up for frustration failure.

    If you've already learned a programming language, then you should have the feel for how a good book is laid out. You learn the structure of the language. The fundamental data types. The flow control. The statements that form the core of the language. The functions and libraries most commonly used. Examples of problem solving.

    If you're an experienced programmer, you can learn the structure of most languages fairly quickly. Maybe even in that mythical 21 day or even 24 hour window. However, after that is actually using it effectively and that will take much longer.

    Note that in terms to structure, C is very simple language. Conversely, C++ is a gigantic hot mess that will take a long time to get a handle of all the syntax, if anyone ever actually does.

    Don't be in a rush. And, for your own sake, don't try to skip the basics.
  2. In Topic: Issue adding multiple functions

    Posted 4 Jul 2015

    Heh, don't mind us: we tend to get pedantic about semantics. ;)

    Learning is good. I want you to know two things: never use the center tag and you almost never need the br tag. As an addendum, sites like this can help a lot: https://validator.w3.org/

    As an example, for your markup, you could do something like:
    <!DOCTYPE html>
    <html>
    <head>
      <title>Test</title>
      <style type="text/css">
        #content {
          margin-top: 4em;
          text-align: center;
        }
      </style>
    </head>
    <body>
    
    <div id="content">
      <dl>
        <dt>Select your shipment amount of <b>COPPER</b></dt>
        <dd>
          <input type="range" min="0" max="200" value="0" onchange="copperValue(this.value)" />
          <div id="copperRange">0</div>
          <div id="copperTotal">0</div>
        </dd>
    
        <dt>Select your shipment amount of <b>SILVER</b></dt>
        <dd>
          <input type="range" min="0" max="5" value="0" onchange="silverValue(this.value)" />
          <div id="silverRange">0</div>
          <div id="silverTotal">0</div>
        </dd>
    
        <dt>Select your shipment amount of <b>GOLD</b></dt>
        <dd>
          <input type="range" min="0" max="4" value="0" onchange="goldValue(this.value)" />
          <div id="goldRange">0</div><br>
          <div id="goldTotal">0</div>
        </dd>
    
        <dt><h3>Total</h3></dt>
        <dd><div id="newTotal">0</div></dd>
    
      </dl>
    </div>
    
    <script type="text/javascript">
    //....
    </script>
    </body>
    </html>
    
    


    Here, we've gotten rid of those br tags, maintained the center you wanted, an allowed for all kinds of styling fun. It's generally considered good form to template in plain ole html as much as possible. Part of the reasoning is that if your javascript should crash, the user at least sees something.

    However, if your page requires javascript to even make sense, you might consider going all in. Here I use the excessively popular library jQuery and draw nearly the entire page in code.
    <!DOCTYPE html>
    <html>
    <head>
      <title>Test</title>
      <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
      <style type="text/css">
        #content {
          margin-top: 4em;
          text-align: center;
        }
      </style>
    </head>
    <body>
    
    <div id="content"></div>
    
    <script type="text/javascript">
    var Data = [
      { name: 'Copper', rangeMin: 0, rangeMax: 200, calc: function(x) { return x * (66.20 / 160 * 1.2); } },
      { name: 'Silver', rangeMin: 0, rangeMax: 5, calc: function(x) { return x * (16.36 * 1.2); } },
      { name: 'Gold', rangeMin: 0, rangeMax: 4, calc: function(x) { return x * (38.99 * 1.2); } }
    ];
    
    $(function () {
        var table = $("<table border='1'>").appendTo("#content");
        $("<thead><tr><th>Resource</th><th>Select</th>><th>Units</th><th>Total</th></tr></thead>").appendTo(table);
        var tbody = $("<tbody>").appendTo(table);
        $.each(Data, function(i, x) { initData(x, $("<tr>").appendTo(tbody)); });
        var grandTotalDiv = $("<div>").appendTo("<td>").appendTo($("<tr><td colspan='3'>Grand Total</td>").appendTo(tbody));
        $.each(Data, function(i, x) { x.updateValues(); });
    
        function initData(data, tr) {
          $("<td>").html(data.name).appendTo(tr);
          data.value = 0;
          data.eleRange = 
            $('<input type="range" min="' + data.rangeMin + '" max="' + data.rangeMax + '" value="' + data.value + '">')
              .appendTo($("<td>").appendTo(tr));
          data.unitDiv = $('<div>').appendTo($("<td>").appendTo(tr));
          data.totDiv = $('<div>').appendTo($("<td>").appendTo(tr));
          data.updateValues = function() {
            data.value = data.eleRange.val();
            data.total = data.calc(data.value);
            data.unitDiv.html(data.value);
            data.totDiv.html(data.total);
            updateTotal();
          };
          data.eleRange.change(data.updateValues);
        }
    
        function updateTotal() {
          var tot = 0;
          $.each(Data, function(i, x) { tot += x.total; });
          grandTotalDiv.html(tot);
        }
    });
    </script>
    </body>
    </html>
    
    


    Keep learning and if you don't follow something here, don't sweat it; you will. Maybe this context will inspire you to go learn something new now. Have fun.
  3. In Topic: Issue adding multiple functions

    Posted 3 Jul 2015

    Indeed:

    Quote

    The following list describes syntax rules for the the HTML syntax. Rules for the the XML syntax are defined in the XML specification.
    -- http://www.w3.org/TR...ml#void-element


    Sorry, if an XML parser coughs up blood on my HTML I consider it less than useful. However, you are correct, in some HTML specs you can be non conformant to XML. I don't know why you would wish to be, but you can.

    However, as br is mostly a non semantic crutch, you'll find few modern sources that will defend it's use over proper CSS.
  4. In Topic: Issue adding multiple functions

    Posted 3 Jul 2015

    Ideally, you'd store the value you calculate rather than just loose it to text in the html. You could store it as you set it and get rid of that awful innerHTML repetition.

    I'm just going to throw this out there. Please read carefully and feel free to ask questions.
    <!DOCTYPE html>
    <html>
    <body>
    <script type="text/javascript">
    // normally you'd want the script element at the end, 
    // but it shouldn't hurt anything here
    
    // an object to hold values, initial values set
    var Values = { copperRange: 0.0, silverRange: 0.0, goldRange: 0.0 };
    
    // set value for both doc elements and our object
    // this allows us to look up values without worrying about DOM stuff
    function setValue(id, value) {
      var e = document.getElementById(id);
      // we can store values that don't actually map to DOM, if we like
      if (e) { e.innerHTML = value; } 
      Values[id] = value;
    }
    
    // when we set a value via this, we also want to update several other values, so make the call
    function updateValue(id, value) {
      setValue(id, value);
      onUpdateValue();
    }
    
    function onUpdateValue() {
      // do the math
      setValue("copperTotal", Values.copperRange * (66.20/160*1.2));
      setValue("silverTotal", Values.silverRange * (16.36*1.2));
      setValue("goldTotal", Values.goldRange * (38.99*1.2));
      setValue("newTotal", Values.copperTotal + Values.silverTotal + Values.goldTotal);
    }
    
    // the functions our form calls
    function copperValue(value) { updateValue("copperRange", value); }
    function silverValue(value) { updateValue("silverRange", value); }
    function goldValue(value) { updateValue("goldRange", value); }
    
    // on the initial load, just set all the zeros
    onUpdateValue();
    </script>
    
    
    <center><!-- this tag has been deprecated since 1999 -->
      <!-- a br tag, particularly one not closed, should raise all kinds of red flags -->
      <br><br><br><br><!-- Seriously time to learn CSS -->
      <p> Select your shipment amount of <b>COPPER</b></p>
      <input type="range" min="0" max="200" value="0" onchange="copperValue(this.value)" />
      <span id="copperRange">0</span><br>
      <span id="copperTotal">0</span><br><br>
      <p> Select your shipment amount of <b>SILVER</b></p>
      <input type="range" min="0" max="5" value="0" onchange="silverValue(this.value)" />
      <span id="silverRange">0</span><br>
      <span id="silverTotal">0</span><br><br>
      <p> Select your shipment amount of <b>GOLD</b></p>
      <input type="range" min="0" max="4" value="0" onchange="goldValue(this.value)" />
      <span id="goldRange">0</span><br>
      <span id="goldTotal">0</span>
      <h3> Total </h3>
      <span id="newTotal">0</span>
    
    </center>
    </body>
    </html>
    
    


    Hope this helps.
  5. In Topic: Stupid Spacing

    Posted 3 Jul 2015

    Ok, I do see a major bug in your writeFile:
    void writeFile(char file[], char output[][3], char newfile[])
    {
       ofstream fout(newfile);
       for (int row = 0; row < 3; row++)
       {
          for (int col = 0; col < 3; col++)
          {
             fout << output[row][col];
          }
          fout << endl;
          // you've only written one row
          // don't close now
          fout.close(); 
       }
       cout << "File written\n";
    
    }
    
    


    You have too many magic numbers floating around in here. Particularly the "." to " " transformation. Define your const. Your save and load file is essentially a single string. e.g.
    #include <iostream>
    #include <fstream>
    
    const int ROWS = 3;
    const int COLS = 3;
    const char C_X = 'X';
    const char C_O = 'O';
    const char C_EMPTY = '.';
    
    typedef char Board[ROWS][COLS];
    
    void display(Board);
    bool writeFile(std::ostream &, Board);
    bool writeFile(const char *filename, Board);
    bool readFile(std::istream &, Board);
    bool readFile(const char *filename, Board);
    
    bool writeFile(const char *filename, const std::string &);
    
    using namespace std;
    
    int main() {
        const char *fn1 = "ttt1.txt";
        const char *fn2 = "ttt2.txt";
        // make a test file
        // note the helper function
        writeFile(fn1, "XO.....X.");
    
        Board b;
        if (!readFile(fn1, B)/>) {
            cout << "couldn't read " << fn1 << endl;
            return 1;
        }
        display(B)/>;
    
        cout << "writing: "; writeFile(cout, B)/>; cout << "." << endl;
    
        if (!writeFile(fn2, B)/>) {
            cout << "couldn't write " << fn2 << endl;
            return 1;
        }
    
        Board b2;
        if (!readFile(fn2, b2)) {
            cout << "couldn't read " << fn2 << endl;
            return 1;
        }
        display(b2);
    
        return 0;
    }
    
    
    void display(Board B)/> {
        for (int row = 0; row < ROWS; row++) {
            for (int col = 0; col < COLS; col++) {
                char c = b[row][col];
                cout << " " << (c==C_EMPTY?' ':c);
                if (col < COLS-1) { cout << " |"; }
            }
            cout << " " << endl;
            if (row < ROWS-1) { cout << "---+---+---"; }
            cout << endl;
        }
    }
    
    


    Results:
     X | O |   
    ---+---+---
       |   |   
    ---+---+---
       | X |   
    
    writing: XO.....X.
    .
     X | O |   
    ---+---+---
       |   |   
    ---+---+---
       | X |   
    
    
    


    Note, as long as you test for your non magic chars, you should be able to verify your read. e.g.
    bool readFile(istream &in, Board B)/> {
        char c; // to read a single char into
        int size = ROWS * COLS;
        int count = 0;
        // your code here
            if (c==C_X || c==C_O || c==C_EMPTY) {
        // your code here
        return count==size;
    }
    
    


    Hope this helps.

My Information

Member Title:
Dreaming Coder
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Location:
Jersey, be afraid.
Years Programming:
25
Programming Languages:
Most.

Contact Information

E-mail:
Click here to e-mail me
Website URL:
Website URL  http://

Comments

  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  1. Photo

    mireille4U Icon

    30 Apr 2015 - 05:26
    Greeting from mireille i saw your profile today and i became interested in you and i will like to know more about you and if you can mail an email to my mail address (mireille4u@live.com) i will give you my picture.here is my mail address i hope we can move from here.above. Mireille
  2. Photo

    ImChicago Icon

    17 Mar 2015 - 17:34
    Hey, im new to coding, how do you recommend starting? What should I master first? Should I use a website to help me?
  3. Photo

    8byte Icon

    10 Jan 2014 - 11:08
    Awesome, thanks for all the help!
  4. Photo

    codiddle Icon

    07 Mar 2013 - 18:59
    GENIUS GUY HERE MAN. Write a book!
  5. Photo

    mamelove25 Icon

    19 Feb 2013 - 10:53
    Hello My Dear, My Name is Mame. i saw your profile today and became interested in you,i will also like to know you more,and if you can send an email to my email address,i will give you my pictures here is my email address (mame25live@yahoo.co.uk) I believe we can move from here! Am waiting for your mail to my email address above because i have much to tell you,
    love Miss Mame.
  6. Photo

    bilbil0629 Icon

    24 Oct 2012 - 05:39
    hey! you mongolian?
  7. Photo

    Ticon Icon

    20 Aug 2012 - 13:23
    I just noticed your an expert in cheese. I lol'd
  8. Photo

    mostyfriedman Icon

    18 Aug 2012 - 23:13
    Hello there Brett
  9. Photo

    MehrdadSecret Icon

    26 Jul 2012 - 05:51
    hello, can i have a contact email or Yahoo or something? Need ur help badly
  10. Photo

    Jeet.in Icon

    18 Apr 2012 - 23:17
    Thanks ! Solved My problem !
    http://www.dreamincode.net/forums/topic/275578-simple-whitespace-remover/page__gopid__1603556&#entry1603556
  11. Photo

    RetardedGenius Icon

    25 Oct 2011 - 14:29
    I agree so much with your opinion of incompetent CS teachers. So true!
    http://www.dreamincode.net/forums/topic/252848-venting-a-frustration/page__view__findpost__p__1469659
  12. Photo

    WabiSabi Icon

    21 Oct 2011 - 11:00
    I agree with assert(C). However, I'd rather not specify what you are "the best" at.
  13. Photo

    assert(C) Icon

    20 Oct 2011 - 08:38
    You are the best
  14. Photo

    macosxnerd101 Icon

    30 Sep 2011 - 09:33
    Congrats on hitting the big 3k!
  15. Photo

    sjin Icon

    16 Aug 2011 - 18:41
    This guy is AWESOME! Cheers bro!
  • (3 Pages)
  • +
  • 1
  • 2
  • 3