Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int key=1.1, mouse=.67, finger=.83;
  5. const char d=0.97, l=1.12, p=1.14, t=1.235;
  6.  
  7. int main(){
  8. int sharp, age;
  9. double PI_h, PI_c, PI_a;
  10. char edu, screen, loop='y';
  11. string inputdev;
  12.  
  13. //loops once and ask to loop again. will loop while loop=='y'
  14. while(loop=='y'){
  15.  
  16. //asking for user input to define variables
  17. cout << "CSOZT Brain Trainer\n";
  18. cout << endl;
  19. cout << "Education level (a, c, or h): ";
  20. cin >> edu;
  21. cout << "Mental sharpness (1-10): ";
  22. cin >> sharp;
  23. cout << "Age (in years): ";
  24. cin >> age;
  25. cout << "Input device (keyboard, mouse, finger): ";
  26. cin >> inputdev;
  27. cout << "Screen size (d, l, p, t): ";
  28. cin >> screen;
  29.  
  30. //sets output to show 3 decimal places
  31. cout.setf(ios::fixed);
  32. cout.showpoint;
  33. cout.precision(3);
  34.  
  35. //formulae to calculate PI for each education level
  36. PI_h=5.17*(393+(6.3*sharp*sharp))/(1.117213218*age);
  37. PI_c=3.71*(405+(5.8*sharp*sharp))/(2.2913513322*age);
  38. PI_a=5.72*(513+(3.9*sharp*sharp))/(1.755249215*age);
  39.  
  40. //adjusts PIs based on input device
  41. if(inputdev=="keyboard"){
  42. key*PI_h, key*PI_c, key*PI_a;
  43. }
  44. else if(inputdev=="mouse"){
  45. mouse*PI_h, mouse*PI_c, mouse*PI_a;
  46. }
  47. else if(inputdev=="finger"){
  48. finger*PI_h, finger*PI_c, finger*PI_a;
  49. }
  50. else{
  51. cout << "Invalid input device";
  52. return 0;
  53. }
  54.  
  55. //switch statement to test screen size and adjust PI
  56. switch(screen){
  57. case 'd':
  58. d*PI_h, d*PI_c, d*PI_a;
  59. break;
  60. case 'l':
  61. l*PI_h, l*PI_c, l*PI_a;
  62. break;
  63. case 'p':
  64. p*PI_h, p*PI_c, p*PI_a;
  65. break;
  66. case 't':
  67. t*PI_h, t*PI_c, t*PI_a;
  68. break;
  69. default:
  70. cout << "Invalid screen type";
  71. return 0;
  72.  
  73. // compares edu to determine which PI calculation to output
  74. if(edu=='a'){
  75. //overrides output of PI_edu for sharpness 3 or lower
  76. if(sharp<=3){
  77. cout << "PI = " << PI_h << endl;
  78. }
  79. else{
  80. cout << "PI = " << PI_a << endl;
  81. }
  82. }
  83. if(edu=='c'){
  84. if(sharp<=3){
  85. cout << "PI = " << PI_h << endl;
  86. }
  87. else{
  88. cout << "PI = " << PI_c << endl;
  89. }
  90. }
  91. else if(edu=='h'){
  92. cout << "PI = " << PI_h << endl;
  93. }
  94.  
  95. //ask to repeat program
  96. cout << "Repeat calculation (y/n): ";
  97. cin >> loop;
  98. }
  99. return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement