Skip to content

Instantly share code, notes, and snippets.

@ChrisLundquist
Forked from anonymous/gist:1268986
Created October 6, 2011 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisLundquist/1268993 to your computer and use it in GitHub Desktop.
Save ChrisLundquist/1268993 to your computer and use it in GitHub Desktop.
// Lab 2
// Jeff Heesch
// 10/5/11
// Purpose: To perform mathematical operations on two numbers
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
// Declare variables
int remainder, x, y;
double num1, num2, sum, difference, product, quotient;
double squareroot1, squareroot2, power1, power2, ceiling1, ceiling2;
// Get user input
cout << "Please enter a number: ";
cin >> num1;
do {
cout << "Please enter another (non zero) number: ";
cin >> num2;
} while(num2 == 0)
// Mathy stuff
x=num1;
y=num2;
sum=num1+num2;
difference=num1-num2;
product=num1*num2;
quotient=num1/num2;
remainder=x%y;
squareroot1=sqrt(num1);
squareroot2=sqrt(num2);
power1=pow(num1,num2);
power2=pow(num2,num1);
ceiling1=ceil(num1);
ceiling2=ceil(num2);
// Output
cout << num1 << " + " << num2 << " is " << sum << endl;
cout << num1 << " - " << num2 << " is " << difference << endl;
cout << num1 << " x " << num2 << " is " << product << endl;
cout << num1 << " / " << num2 << " is " << quotient << endl;
cout << num1 << " % " << num2 << " is " << remainder << endl;
cout << num1 << " raised to " << num2 << " is " << power1 << endl;
cout << num2 << " raised to " << num1 << " is " << power2 << endl;
cout << "The squareroot of " << num1 << " is " << squareroot1 << endl;
cout << "The squareroot of " << num2 << " is " << squareroot2 << endl;
cout << num1 << " rounded up is " << ceiling1 << endl;
cout << num2 << " rounded up is " << ceiling2 << endl;
return(0);
} // End Main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment