Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int key=1.1, mouse=.67, finger=.83;
- const char d=0.97, l=1.12, p=1.14, t=1.235;
- int main(){
- int sharp, age;
- double PI_h, PI_c, PI_a;
- char edu, screen, loop='y';
- string inputdev;
- //loops once and ask to loop again. will loop while loop=='y'
- while(loop=='y'){
- //asking for user input to define variables
- cout << "CSOZT Brain Trainer\n";
- cout << endl;
- cout << "Education level (a, c, or h): ";
- cin >> edu;
- cout << "Mental sharpness (1-10): ";
- cin >> sharp;
- cout << "Age (in years): ";
- cin >> age;
- cout << "Input device (keyboard, mouse, finger): ";
- cin >> inputdev;
- cout << "Screen size (d, l, p, t): ";
- cin >> screen;
- //sets output to show 3 decimal places
- cout.setf(ios::fixed);
- cout.showpoint;
- cout.precision(3);
- //formulae to calculate PI for each education level
- PI_h=5.17*(393+(6.3*sharp*sharp))/(1.117213218*age);
- PI_c=3.71*(405+(5.8*sharp*sharp))/(2.2913513322*age);
- PI_a=5.72*(513+(3.9*sharp*sharp))/(1.755249215*age);
- //adjusts PIs based on input device
- if(inputdev=="keyboard"){
- key*PI_h, key*PI_c, key*PI_a;
- }
- else if(inputdev=="mouse"){
- mouse*PI_h, mouse*PI_c, mouse*PI_a;
- }
- else if(inputdev=="finger"){
- finger*PI_h, finger*PI_c, finger*PI_a;
- }
- else{
- cout << "Invalid input device";
- return 0;
- }
- //switch statement to test screen size and adjust PI
- switch(screen){
- case 'd':
- d*PI_h, d*PI_c, d*PI_a;
- break;
- case 'l':
- l*PI_h, l*PI_c, l*PI_a;
- break;
- case 'p':
- p*PI_h, p*PI_c, p*PI_a;
- break;
- case 't':
- t*PI_h, t*PI_c, t*PI_a;
- break;
- default:
- cout << "Invalid screen type";
- return 0;
- // compares edu to determine which PI calculation to output
- if(edu=='a'){
- //overrides output of PI_edu for sharpness 3 or lower
- if(sharp<=3){
- cout << "PI = " << PI_h << endl;
- }
- else{
- cout << "PI = " << PI_a << endl;
- }
- }
- if(edu=='c'){
- if(sharp<=3){
- cout << "PI = " << PI_h << endl;
- }
- else{
- cout << "PI = " << PI_c << endl;
- }
- }
- else if(edu=='h'){
- cout << "PI = " << PI_h << endl;
- }
- //ask to repeat program
- cout << "Repeat calculation (y/n): ";
- cin >> loop;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement