Advertisement
TheQuack45

/r/DailyProgrammer Challenge #138 in C++

Nov 21st, 2014
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. // DailyProgrammerChallenge138InCPP.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. int _tmain(int argc, _TCHAR* argv[])
  10. {
  11.     // Variable declaration
  12.     float mass1;
  13.     float mass2;
  14.     float x1;
  15.     float x2;
  16.     float y1;
  17.     float y2;
  18.     float deltaX;
  19.     float deltaY;
  20.     float distance;
  21.     float force;
  22.  
  23.     // Variable input for particle 1
  24.     cout << "Mass of particle 1" << endl;
  25.     cin >> mass1;
  26.     cout << "X-position of particle 1" << endl;
  27.     cin >> x1;
  28.     cout << "Y-position of particle 1" << endl;
  29.     cin >> y1;
  30.  
  31.     // Variable input for particle 2
  32.     cout << "Mass of particle 2" << endl;
  33.     cin >> mass2;
  34.     cout << "X-position of particle 2" << endl;
  35.     cin >> x2;
  36.     cout << "Y-position of particle 2" << endl;
  37.     cin >> y2;
  38.    
  39.     // Calculations
  40.     deltaX = (x1 - x2);
  41.     deltaY = (y1 - y2);
  42.     distance = sqrt((deltaX * deltaX) + (deltaY * deltaY));
  43.     force = ((mass1 * mass2) / (distance * distance));
  44.  
  45.     cout << "The repulsion force between the two particles is " << force << endl;
  46.    
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement