Skip to content

Instantly share code, notes, and snippets.

@natemcmaster
Created September 19, 2013 23:06
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 natemcmaster/6631090 to your computer and use it in GitHub Desktop.
Save natemcmaster/6631090 to your computer and use it in GitHub Desktop.
Demo of integer math vs. double math
#include <iostream>
using namespace std;
int main(){
int half = 3/2;
cout << half << endl; //Prints 1 because int's throw away the decimal
double intMath= 3 / 2;
cout<<intMath<<endl; //Prints 1, not what we expected
double doubleMath = 3 / 2.0; //Notice that we wrote 2.0, not 2
cout <<doubleMath <<endl; // Prints 1.5
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment