//programmers: Anjum and Fletcher
//file: functions.cpp
#include "functions.h"
#include "constants.h"
void presentMenuOptions()
{
cout<<"\n\tCrime-o-Light 400\n";
cout<<"\t-----------------\n";
cout<<"1. Hair\n";
cout<<"2. Saliva and hair\n";
cout<<"3. Chicken-noodle soup and saliva and hair\n";
cout<<"4. Green Goo\n";
cout<<"5. exit\n";
cout<<"Please select an option: ";
}
void goodbye()
{
cout<<"\nSigning of now ...\n\n";
}
int getInteger(const int min, const int max)
{
int val;
cout<<"Please enter a value between ("<<min<<", "<<max<<"): ";
cin>>val;
while(val<min || val >max)
{
cout<<"Invalid entry ... Please enter a value between ("<<min<<", "<<max<<"): ";
cin>>val;
}
return val;
}
int getInteger(const int min)
{
int val;
cout<<"Please enter an integer greater than "<<min-1<<": ";
cin>>val;
while(val<min)
{
cout<<"Invalid entry ... Please enter an integer greater than "<<min-1<<": ";
cin>>val;
}
return val;
}
bool getBoolean(const string question)
{
int val;
cout<<question<<" Enter 1 for Yes, 0 for No: ";
cin>>val;
while(val!=1 && val!=0)
{
cout<<"Invalid entry ... Enter 1 for Yes, 0 for No: ";
cin>>val;
}
return val == 1? true : false;
}
float getHairIndex()
{
int color;
//while loop to get a valid hair color choice
cout<<"Please enter 1 for blonde, 2 for brown and 3 for black: ";
cin>>color;
while(color!=1 && color!=2 && color!=3)
{
cout<<"Invalid entry ... please enter 1 for blonde, 2 for brown and 3 for black: ";
cin>>color;
}
if(color==1)
return BLONDE_HAIR_INDEX;
else if(color==2)
return BROWN_HAIR_INDEX;
else
return BLACK_HAIR_INDEX;
}
int getAlienHeight()
{
int height;
//while loop to get a valid alien height
cout<<"What is the height of the alien (ft), enter 1, 2 or 3: ";
cin>>height;
while(height!=1 && height!=2 && height!=3)
{
cout<<"Invalid entry ... enter 1, 2 or 3: ";
cin>>height;
}
if(height==1)
return ALIEN_1FT;
else if(height==2)
return ALIEN_2FT;
else
return ALIEN_3FT;
}
float getWavelength(const float hairIndex)
{
return WAVELENGTH_FOR_HAIR*hairIndex;
}
float getWavelength(const int n, const float hairIndex)
{
float wavelength=0;
//for loop for coding formula
for(int i =1;i<=n;i++)
{
wavelength+=(1/static_cast<float>(i));
}
wavelength*=100;
wavelength*=hairIndex;
return wavelength;
}
float getWavelength(const int n, bool isHomeMade)
{
float wavelength=0;
float powerTerm=1;
//nested for loop for coding formula
wavelength+=powerTerm;
for(int i =1;i<n;i++)
{
for(int j =1;j<=i;j++)
{
powerTerm*=(1.0/2);
}
wavelength+=powerTerm;
powerTerm=1;
}
wavelength*=100;
if(isHomeMade)
wavelength*=HOME_MADE_CONSTANT;
return wavelength;
}
float getWavelength(const int gooGrade, const int alienHeight)
{
float wavelength=0;
//using switch case statement to calculate the wavelength
switch(gooGrade)
{
case 6:
wavelength+=GG6;
case 5:
wavelength+=GG5;
case 4:
wavelength+=GG4;
case 3:
wavelength+=GG3;
case 2:
wavelength+=GG2;
case 1:
wavelength+=GG1;
case 0:
wavelength+=GG0;
}
return wavelength*alienHeight;
}