assignment_04.cpp
/*
Program....: assignment_04.cpp
Student....: Michael Rouse
Student ID.:
Class......: Comp Sci 1570 Section D
Instructor.: Fletcher
Date.......: 02/20/2015
Description: Give a user a menu, after input decide the wavelength needed to reveal that object at a crime scene
*/
#include <iostream>
using namespace std;
int main()
{
// Declare Constants for the GOO Grades
const int BASE_GRADE = 200;
const int GRADE_1 = 43; // E.g., Grade 1 = BASE_GRADE + 43 (GRADE_1 Constant)
const int GRADE_2 = 17;
const int GRADE_3 = 23;
const int GRADE_4 = 77;
const int GRADE_5 = 55;
const int GRADE_6 = 35;
// Declare Variables
int iUserChoice; // User Input at the main menu
int iPrecision; // Number for precision on certain menu items
int iGrade; // Grade of the GOO
long iPrecisionPower; // For Option 3
float fWaveLength; // Wavelength required
// Loop until the user exits
do
{
// Reset/Initialize certain variables every loop
fWaveLength = 0.00;
iPrecisionPower = 2;
iGrade = 0;
// Display the menu
cout << "\n\n\tCrime-O-Light 400\n";
cout << "\t-----------------\n\n";
cout << "1. Hair\n";
cout << "2. Saliva and hair\n";
cout << "3. Chicken-noodle soup, saliva, and hair\n";
cout << "4. Green Goo\n";
cout << "5. Exit\n\n";
// Get User Input
cout << "Please choose an option (1-5): ";
cin >> iUserChoice;
cout << "\n\n";
// Choose an option and display the wavelength
switch (iUserChoice)
{
// =================================================
// Hair
// =================================================
case 1:
cout << "Hair will show up with 400 nm light.\n";
break;
// =================================================
// Saliva and hair
// =================================================
case 2:
cout << "Enter precision (between 1 and 8): ";
cin >> iPrecision;
while (iPrecision < 2 || iPrecision >= 8)
{
// Not valid precision
cout << "\nThe precision must be greater than 1 and less than 8.\n";
cout << "Please try again: ";
cin >> iPrecision;
}
// Calculate the wavelength
fWaveLength = 1.0;
for (float fCounter = 2; fCounter <= static_cast<float>(iPrecision); fCounter++)
{
fWaveLength += ( 1.000 / fCounter);
}
fWaveLength *= 100; // multiply by 100
// Print the wavelength
cout << "\nThe wavelength for saliva and hair (precision of " << iPrecision << ") is " << static_cast<int>(fWaveLength) << " nm.\n";
break;
// =================================================
// Chicken Noodle Soup, Saliva, and Hair
// =================================================
case 3:
cout << "Enter precision (greater than 0): ";
cin >> iPrecision;
while (iPrecision < 1)
{
// Not valid precision
cout << "\nThe precision must be greater than 0.\n";
cout << "Please try again: ";
cin >> iPrecision;
}
// Calculate the wavelength
fWaveLength = 1.0;
// Calculate the iPrecision power of 2
for (int iExpCounter = 2; iExpCounter <= iPrecision; iExpCounter++)
{
iPrecisionPower *= 2;
}
cout << "\n" << iPrecisionPower << "\n";
for (float fCounter = 2; fCounter <= static_cast<float>(iPrecisionPower); fCounter *= 2)
{
fWaveLength += (1.00 / fCounter);
}
fWaveLength *= 100; // Multiply by 100
// Print the wavelength
cout << "\nThe wavelength for chicken noodle soup, saliva, and hair is " << static_cast<int>(fWaveLength) << " nm.\n";
break;
// =================================================
// Green Goo
// =================================================
case 4:
cout << "Enter Grade (0-6): ";
cin >> iGrade;
while (iGrade < 0)
{
// Not valid precision
cout << "\nThe grade must be greater than or equal to zero.\n";
cout << "Please try again: ";
cin >> iGrade;
}
switch (iGrade)
{
case 6:
// Grade 6
fWaveLength += GRADE_6;
case 5:
// Grade 5
fWaveLength += GRADE_5;
case 4:
// Grade 4
fWaveLength += GRADE_4;
case 3:
// Grade 3
fWaveLength += GRADE_3;
case 2:
// Grade 2
fWaveLength += GRADE_2;
case 1:
// Grade 1
fWaveLength += GRADE_1;
case 0:
// Grade 0
fWaveLength += BASE_GRADE;
}
// Display the wavelength
cout << "\nThe wavelength for Green Goo (Grade " << iGrade << ") is " << static_cast<int>(fWaveLength) << " nm.\n";
break;
// =================================================
// Exit
// =================================================
case 5:
cout << "\n\nThank you for using the program, have a nice day.\n";
break;
// =================================================
// Unknown
// =================================================
default:
// Whoops?
cout << "\n\nWhoops! Something went wrong, try running the program again.\n";
}
}while(iUserChoice != 5);
cout << "\nGoodbye.\n\n";
return 1;
}