Guest User

Untitled

a guest
Apr 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. float energy(int n, float m, float L);
  9.  
  10. int main () {
  11.  
  12. float Me = 9.109E-31, Mp = 1.67E-27;
  13. double h = 6.626E-34, U;
  14. string name;
  15.  
  16. int Particle = 0;
  17. char P, E;
  18.  
  19. while ((Particle != 'P') || (Particle != 'E')) {
  20.  
  21. cout << "Please enter 'P' to check Proton energy or 'E' for Electron energy." << endl;
  22. if (!(cin >> Particle)) {
  23. cin.clear();
  24. cin.ignore(255,'\n');
  25. }
  26. if ((Particle != 'P') || (Particle != 'E')) {
  27. cout << "The character you have entered is invalid. Please enter 'P' or 'E'." << endl;
  28. }
  29.  
  30. }
  31.  
  32. float State = 0;
  33.  
  34. while (( State < 1) || (State/(int)State !=1)){
  35.  
  36. cout << "Please enter the energy state" << endl;
  37. if (!(cin >> State)) {
  38. cin.clear();
  39. cin.ignore(255,'\n');
  40. }
  41. if (( State < 1) || (State/(int)State !=1));
  42. cout << "Invalid Energy state. Please enter a positive integer for this value." << endl;
  43. }
  44.  
  45. }
  46.  
  47.  
  48. switch (Particle) {
  49. case 'P' :
  50. name = "Proton";
  51. L = 1E-14;
  52. m = Mp;
  53. U = energy((int)State, m, L);
  54. break;
  55. case 'E' :
  56. name = "Electron" ;
  57. L = 1E-10;
  58. m = Me;
  59. U = energy((int)State, m, L);
  60. break;
  61.  
  62.  
  63. }
  64.  
  65. cout << "At n = " << (int)State << " the energy of the " << name << " is " << U/(1.602E-19) << " eV." << endl;
  66. return 0;
  67.  
  68.  
  69.  
  70. float energy(int n, float m, float L) {
  71. return (pow(n,2)*pow(h,2)/(8*m*pow(L,2));
  72. }
Add Comment
Please, Sign In to add comment