Skip to content

Instantly share code, notes, and snippets.

@paranoiacblack
Created October 10, 2012 17:07
Show Gist options
  • Save paranoiacblack/3866959 to your computer and use it in GitHub Desktop.
Save paranoiacblack/3866959 to your computer and use it in GitHub Desktop.
CS 10 SI Classroom Session 2 - Expression Examples
#include <iostream>
using namespace std;
int main() {
// Initialize multiple integer variables on same line.
// Why would I initializing the rightOperand with 1? What am I anticipating?
int leftOperand = 0, rightOperand = 1;
// *Prefer making intermediate variables that store meaningful values instead
// of doing computation in cout statements.
int sum = 0;
int difference = 0;
int product = 0;
int quotient = 0;
int remainder = 0;
// Explain what this software does.
cout << "Welcome to C++-ExpressionMaster" << endl
<< "With this software, you can compute many mathematical expressions"
"with the click of a button!" << endl << endl;
cout << "Currently, this software supports the following operations with"
" two integers:" << endl
<< "\tAddition: I.E. a + b" << endl
<< "\tSubtraction: I.E. a - b" << endl
<< "\tMultiplication: I.E. a * b" << endl
<< "\tQuotient: I.E. a / b" << endl
<< "\tRemainder: I.E. The remainder of a/b" << endl << endl;
// Prompt user to fill in these variables.
cout << "Enter in the left operand for these calculations: ";
cin >> leftOperand;
cout << "Enter in the right operand for these calculations: ";
cin >> rightOperand;
// Now, before outputting the results, store evaluated expressions
// in intermediate variables.
sum = leftOperand + rightOperand;
difference = leftOperand - rightOperand;
product = leftOperand * rightOperand;
quotient = leftOperand / rightOperand;
remainder = leftOperand % rightOperand;
// Remind user about the numbers they entered.
cout << endl;
cout << "The two integers you entered, in order, are "
<< leftOperand << " and " << rightOperand << endl;
// Output computed values.
cout << "Their sum is " << sum << endl
<< "Their difference is " << difference << endl
<< "Their product is " << product << endl
<< "The quotient is " << quotient << endl
<< "The remainder is " << remainder << endl;
return 0;
}
99999999999999999999999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment