Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- #include <string>
- using namespace std;
- float energy(int n, float m, float L);
- int main () {
- float Me = 9.109E-31, Mp = 1.67E-27;
- double h = 6.626E-34, U;
- string name;
- int Particle = 0;
- char P, E;
- while ((Particle != 'P') || (Particle != 'E')) {
- cout << "Please enter 'P' to check Proton energy or 'E' for Electron energy." << endl;
- if (!(cin >> Particle)) {
- cin.clear();
- cin.ignore(255,'\n');
- }
- if ((Particle != 'P') || (Particle != 'E')) {
- cout << "The character you have entered is invalid. Please enter 'P' or 'E'." << endl;
- }
- }
- float State = 0;
- while (( State < 1) || (State/(int)State !=1)){
- cout << "Please enter the energy state" << endl;
- if (!(cin >> State)) {
- cin.clear();
- cin.ignore(255,'\n');
- }
- if (( State < 1) || (State/(int)State !=1));
- cout << "Invalid Energy state. Please enter a positive integer for this value." << endl;
- }
- }
- switch (Particle) {
- case 'P' :
- name = "Proton";
- L = 1E-14;
- m = Mp;
- U = energy((int)State, m, L);
- break;
- case 'E' :
- name = "Electron" ;
- L = 1E-10;
- m = Me;
- U = energy((int)State, m, L);
- break;
- }
- cout << "At n = " << (int)State << " the energy of the " << name << " is " << U/(1.602E-19) << " eV." << endl;
- return 0;
- float energy(int n, float m, float L) {
- return (pow(n,2)*pow(h,2)/(8*m*pow(L,2));
- }
Add Comment
Please, Sign In to add comment