TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ROBERT DAVIES
from: CAMERON CLARK
date: 1997-10-11 16:07:00
subject: Re: Advice

RD> been advised to find a book with Watcom in the name. I am new to c/c++
RD> programming but know a little Basic, any help would be graetly 
appreciated.
    There's quite a gap inbetween Basci and C/C++. You may want to start
    with a simpler strongly typed language (like pascal).
    Otherwise, I've found that all one needs to know about a language
    to start writing is a few basic ideas.
    Iteration,Loops,Decision statements, normal statements.
    Normal statements::
    void main() {
      int a,b,c;     // these variable are not initilized
      a = 5;         // assignment
      a = a + 1;     // increment
      a += 1;        // means a = a + 1;
      b = 10;        // assignment
      c = b;         // assignment
      a = b * c;     // multiplication
      a = b / c;     // division
      a = b - c;     // subtration
      a = b % c;     // modulo
      a++;           // increments after statement is finished
      ++a;           // increments before variable is used
      a = b++ * c++;  // a = b * c; b +=1; c+=1;
      a = ++b * ++c;  // a = (b+1) * (c+1);
    }
    iteration/loops
    for (int i=0; i<10; i++);  // new loop variable; continute condition;
                               // variable adjustment
    This means loop from 0 to 9 by 1 step at a time
    for (int i=0; i<20; i+=2) {
      cout << "i =" << i << endl;      
    }
    // cout is the standard output stream. It writes to the screen.
    // you must use #include  at the start of the program
    // to include the input/output stream library
    do {
    } while (i==10);
    // this loop while loop while i is equal to 10
    // notice that '==' is comparison and '=' is assignment
    while (i != 10) {
    }
    // this loop will execute if i is not (!) equal to 10
    
  
    DECISIONS
    if (a==b) {
      // a is equal to b
    } else if (a==c) {**
      // a is equal to c
    } else {
      // a is not equal to b or equal to c
    }
    if (a==10) {
      // a is equal to 10
    }
    
    switch(a) {
    case 0: { // a is 0
              break;            // this says stop and exit the switch
            }
    case 1: { // a is 1
              break;
            }             
    case 2:
    case 3:
    case 4: { // a is 2,3, or 4
              break;
            }
    defualt: {
            // a is not 0 through 4
    }
    } // end of switch
    Switch statements require an integer, character, or any other
    enumerated type (meaning no decimals or strings or anything that's
    not discrete)
    That's all you need to get started (decisions, loops, and statements).
    There are LOTS of details and other syntax to learn, but I gave
    you enough to translate from Basic to C/C++.
    NOTE: Unlike Basic, C/C++ is strongly typed. This means you must
    declare a variable before you use it.
    EG
    { int a = 1;
      a *= 2;     // a = a * 2;
      int b = 2;
      a += b;     // a = a + b;
      double c = 0.5;
      c *= a * b;   // c = c * a * b;
     // note that integers are promoted to doubles in order to mix
    // integer and double arithmatic
    
    
--- GEcho 1.00
---------------
* Origin: Digital OnLine Magazine! - (409)838-8237 (1:3811/350)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.