// Programmer: Clayton Price
// File: hw3.cpp
// Description: This file contains the main function for the program that will
// compute a ocular prescription for Milhouse
#include <iostream>
using namespace std;
int main()
{
//constants for the program
const string CODE_PART1_OPT1 = "P"; //first parts of code
const string CODE_PART1_OPT2 = "B";
const string CODE_PART1_OPT3 = "C";
const short CODE_PART1_OPT1MAX = 5; //limits for part 1
const short CODE_PART1_OPT2MAX = 10;
const short MIN_CORNEA = 1; //limits for cornea measure
const short MAX_CORNEA = 20;
const long MAGIC_FORMULA_CONST1 = 7919; //constants for the magic
const long MAGIC_FORMULA_CONST2 = 104729; // formula
const long MAGIC_FORMULA_CONST3 = 101;
const long MAGIC_FORMULA_CONST4 = 150;
const short CODE_PART2_OPT1MIN = 150; //range limits for figuring
const short CODE_PART2_OPT1MAX = 200; // part 2
const short CODE_PART2_OPT2MIN = 201;
const short CODE_PART2_OPT2MAX = 250;
const string CODE_PART2_OPT1 = "iN"; //second parts of code
const string CODE_PART2_OPT2 = "Li";
const string CODE_PART3_OPT1 = "N"; //third parts of code
const string CODE_PART3_OPT2 = "Ke";
const string CODE_PART3_OPT3 = "P";
const string CODE_PART4_OPT1 = "d"; //fourth parts of code
const string CODE_PART4_OPT2 = "ky";
const string CODE_PART4_OPT3 = "h";
const string CODE_PART4_OPT4 = "ye";
const short MAX_SNELLEN_LINE = 9; //number of lines on a snellen
//variables
string part1; //parts of the code
string part2;
string part3;
string part4;
string name; //user's name for friendliness
long start;
long magic_form_part1, magic_form_part2;
float magic_formula;
short cornea;
short snellen_error; //line num for first error on snellen chart
// input info from user and compute code **********
cout<<"\n\n\n\tVISION PRESCRIPTIFIER"<<endl<<endl;
cout<<"Please enter your name: ";
cin>>name;
cout<<"OK, "<<name<<", now measure your cornea and enter here: ";
cin>>cornea;
while (cornea < MIN_CORNEA || cornea > MAX_CORNEA)
{
cout<<"\tUnacceptable measure. Enter again: ";
cin>>cornea;
}
// now cornea between MIN AND MAX cornea measures
// figuring part 1 of code***********************
if (cornea < CODE_PART1_OPT1MAX)
part1 = CODE_PART1_OPT1;
else if (cornea < CODE_PART1_OPT2MAX)
part1 = CODE_PART1_OPT2;
else
part1 = CODE_PART1_OPT3;
// figuring part 2 of code***********************
// computing magic formula values
if (part1 == CODE_PART1_OPT1)
start = 1;
else if (part1 == CODE_PART1_OPT2)
start = 2;
else
start = 3;
magic_form_part1 = (start * MAGIC_FORMULA_CONST1 + MAGIC_FORMULA_CONST2) %
MAGIC_FORMULA_CONST3 + MAGIC_FORMULA_CONST4;
start = magic_form_part1;
magic_form_part2 = (start * MAGIC_FORMULA_CONST1 + MAGIC_FORMULA_CONST2) %
MAGIC_FORMULA_CONST3 + MAGIC_FORMULA_CONST4;
magic_formula = (magic_form_part1 + magic_form_part2)/2.0;
if (CODE_PART2_OPT1MIN <= magic_formula
&& magic_formula <= CODE_PART2_OPT1MAX)
part2 = CODE_PART2_OPT1;
else if (CODE_PART2_OPT2MIN <= magic_formula
&& magic_formula <= CODE_PART2_OPT2MAX)
part2 = CODE_PART2_OPT2;
// now for part 3 of the code **********************
do
{
cout<<"Please enter the upper-most line of Snellen chart with error: ";
cin>>snellen_error;
} while ( snellen_error < 1 || snellen_error > MAX_SNELLEN_LINE);
if (snellen_error == 1)
part3 = CODE_PART3_OPT1;
else if (snellen_error == 2)
part3 = CODE_PART3_OPT2;
else
part3 = CODE_PART3_OPT3;
// and part 4 of the code *********************************
if ((part1 == CODE_PART1_OPT1 || part1 == CODE_PART1_OPT2) &&
snellen_error == 1)
part4 = CODE_PART4_OPT1;
else if (part1 == CODE_PART1_OPT3 && snellen_error == 1)
part4 = CODE_PART4_OPT2;
else if (part2 == CODE_PART2_OPT1 && snellen_error >= 3)
part4 = CODE_PART4_OPT3;
else
part4 = CODE_PART4_OPT4;
// output of code ******************************************
cout<<endl<<name<<", ok, your code is: "<<part1<<part2<<part3<<part4
<<endl;
cout<<"Well, good luck earthman witht he lifestyle......"<<endl;
return 0;
}