Created
October 10, 2012 17:07
-
-
Save paranoiacblack/3866959 to your computer and use it in GitHub Desktop.
CS 10 SI Classroom Session 2 - Expression Examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 | |
0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 | |
13 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99999999999999999999999 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment