#include "stdio.h" #include #include "math.h" using namespace std; double output ( double input1, double input2 ); //ignore this at first int main ( int argc, char** argv ) { //today's lesson #1: variable declarations and storage review; quick ops // do not copy my comment statements today! double a; int b; float c; //allowed to put multiple lines on one with ; double beta = 0.1; //beta created and value stored, until it gets changed a = (beta * 8. - 1.) / 3.; //variables can be used in equations. Periods optional b = 1; b++; b--; //same as b += 1 and b -= 1 which are same as b=b+1 and b=b-1 a /= 3.; a *= 4.; //same as a = a/3 and a = a*4 //lesson #2: arrays, 2D and higher double position[3]; position[0] = 2.7; //arrays start at 0 NOT 1 in C/C++ (argv is only exception!) position[1] = 3.1; position[2] = 1.6; //if you try to access element [3] you would get a seg fault int cool_numbers[4] = { 5, 6, 7, 8 }; float MatricesAreFun[9][5]; //lesson #3: commenting out entire code blocks /*if ( a < 0 ) { fprintf(stderr,"I don't like your numbers!\n"); } else if ( a == 0 ) { cout << "Argh, zero!!" << endl; } else { cout << "You are awesome!" << endl; }*/ //lesson #4: the switch statement (vs. if/else) switch ( b ) { //expression inside () must be an integer or equivalent case -1: //this is the value of the integer b being checked cout << "Cold!" << endl; break; //break tells it to stop checking the rest case 0: cout << "Neutral!" << endl; break; case 1: //you can have as many cases as you would like cout << "Hot!" << endl; break; default: //default case recommended. It's like an else. No break needed. cout << "WTH?!" << endl; } //lesson #5: function calls double yo = output(2.,3.); cout << yo << "\t" << endl; //Next time: rand's, loops, debugging, file reading, strings return 1; } double output ( double input1, double input2 ) { double spitOut = input1 * 2. + input2; //could separate out return spitOut; //something was done to input, then new result returned }