ok, it's working now. the code's still kinda messy though.
here's what I have now:
Code:
// Health Fair
// Created by Ty Guenley
// 02-09-05
#include <iostream.h>
// Required header and namespace for colors
#include "Console.h"
namespace con = JadedHoboConsole;
// Defining Necessary Variables
int pounds, feet, inches, activity, calories, wselect;
float meters, kilograms;
char bmireturn, wreturn;
// Body Mass Index Inline Function
inline void bmi()
{
// Defining Body Mass Index Variable
float bmi;
// Streams required for colors
using std::cout;
using std::endl;
// Clear Screen
cout << con::clr;
// Body Mass Title and Intro
cout << con::fg_gray << "-" << con::fg_white << "=" << con::fg_cyan << "Body Mass Index"
<< con::fg_white << "=" << con::fg_gray << "-";
// Get User's Height and Weight
cout << con::fg_white << "\n\nEnter your " << con::fg_cyan
<< con::bg_blue << "WEIGHT" << con::fg_white << con::bg_black << "in pounds: ";
cin >> pounds;
cout << con::fg_white << "\n\nEnter your " << con::fg_cyan
<< con::bg_blue << "HEIGHT" << con::fg_white << con::bg_black << "... ";
cout << "\n\tFeet: ";
cin >> feet;
cout << "\tInches: ";
cin >> inches;
// Make Calculatations
inches = (feet * 12) + inches;
meters = inches * (float)0.0254;
kilograms = pounds / (float)2.2;
bmi = kilograms / (meters * meters);
// Display Results
cout << "\nYou are " << con::fg_cyan << meters << "m"
<< con::fg_white << " tall.";
cout << "\nYour mass is " << con::fg_cyan << kilograms << "kg" << con::fg_white << ".";
cout << "\nYour Body Mass Index is " << con::fg_cyan << bmi << con::fg_white << ".";
// Return to main()?
bmim:
cout << "\n\nWould you like to return to the main menu? "
<< con::fg_gray << "y/n: ";
cin >> bmireturn;
switch (bmireturn)
{
case 'y':
return;
case 'n':
cout << con::fg_white << "\nGood-bye!";
break;
default:
cout << con::clr;
cout << con::fg_white << "\nPlease choose y/n!";
goto bmim;
break;
}
}
// Weight Loss Inline Function
inline void weight()
{
using std::cout;
using std::endl;
// Clear Screen
cout << con::clr;
// Weight Loss Title
cout << con::fg_gray << "-" << con::fg_white << "="
<< con::fg_cyan << "Weight Loss" << con::fg_white
<< "=" << con::fg_gray << "-\n\n";
cout << con::fg_white << "Please enter your Activity level:";
cout << con::fg_cyan << "\n\n1. " << con::fg_white << "Sedentary";
cout << con::fg_cyan << "\n2. " << con::fg_white << "Physically active, 3+ times"
<< " a week at 60-80% of maximum heart rate";
cout << con::fg_cyan << "\n3. " << con::fg_white << "Pregnant/nursing";
cout << con::fg_cyan << "\n4. " << con::fg_white << "Varsity athlete or physical laborer";
cout << "\n\nPlease make a selection: ";
cin >> wselect;
switch (wselect)
{
case 1:
activity = 12;
break;
case 2:
activity = 15;
break;
case 3:
activity = 18;
break;
case 4:
activity = 20;
break;
default:
cout << con::fg_yellow << con::bg_gray << "/" << con::fg_gray << con::bg_yellow << "/"
<< con::fg_yellow << con::bg_gray << "/" << con::fg_white << con::bg_red
<< "Error: Please enter a valid choice!" << con::fg_yellow << con::bg_gray << "/"
<< con::fg_gray << con::bg_yellow << "/" << con::fg_yellow << con::bg_gray << "/\n"
<< con::fg_white << con::bg_black;
break;
}
if (!pounds) {
cout << con::fg_white << "\n\nEnter your " << con::fg_cyan
<< con::bg_blue << "WEIGHT" << con::fg_white << con::bg_black << "in pounds: ";
cin >> pounds;
}
calories = activity * pounds;
cout << con::fg_white << "\nYou need " << con::fg_cyan << calories << " calories"
<< con::fg_white << " per day to maintain your current weight.";
cout << con::fg_white << "\nYou need " << con::fg_cyan << (calories - 500) << " calories"
<< con::fg_white << " per day to lose a pound a week.";
if (wselect != 2) {
cout << con::fg_white << "\nIf you excersized 3+ times a week, you would need "
<< con::fg_cyan << (calories - 250) << " calories" << con::fg_white
<< " per day to lose weight.";
wmenu:
cout << "\n\nWould you like to return to the main menu? "
<< con::fg_gray << "y/n: ";
cin >> wreturn;
switch (wreturn)
{
case 'y':
return;
case 'n':
cout << con::fg_white << "\nGood-bye!";
break;
default:
cout << con::clr;
cout << con::fg_white << "\nPlease choose y/n!";
goto wmenu;
break;
}
}
}
// Main Menu Function
void menu()
{
// Defining Menu Selection Variable
int select;
using std::cout;
using std::endl;
while (true) {
// Main Title and Copyleft
cout << con::clr;
cout << con::fg_gray << "-" << con::fg_white << "=" << con::fg_cyan << "Health Fair 2005"
<< con::fg_white << "=" << con::fg_gray << "-\t(L)2005 Ty Guenley";
// Menu Selection
cout << con::fg_white << "\n\n\t::" << con::fg_gray
<< "Menu" << con::fg_white << "::";
cout << con::fg_cyan << "\n\n1. " << con::fg_white << "Body Mass Index";
cout << con::fg_cyan << "\n2. " << con::fg_white << "Weight Loss";
cout << con::fg_cyan << "\n3. " << con::fg_white << "Quit";
cout << "\n\nPlease make a selection: ";
cin >> select;
// Menu Selection Functions
// If-Else If used to prevent recursion when functions return
if (select == 1) {
bmi();
}
else if (select == 2) {
weight();
}
else if (select == 3) {
break;
}
else {
cout << con::fg_yellow << con::bg_gray << "/" << con::fg_gray << con::bg_yellow << "/"
<< con::fg_yellow << con::bg_gray << "/" << con::fg_white << con::bg_red
<< "Error: Please enter a valid choice!" << con::fg_yellow << con::bg_gray << "/"
<< con::fg_gray << con::bg_yellow << "/" << con::fg_yellow << con::bg_gray << "/\n"
<< con::fg_white << con::bg_black;
cin.get();
}
}
}
int main()
{
menu();
return 0;
}
any more tips?
what exactly would the cin.ignore(80,'\n'); do?
Edit: Actually, it's not QUITE working. When you choose not to go to the main menu, it goes anyways. After the break; it's returning anyways. Is there a way to keep it from returning and just terminate?