Who have c++ program that include string,pointer and 2D array?
here is my codes..would u help me where should i put the pointer?
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <windows.h>
using namespace std;
const int maxUser = 100;
float w, healthyw, h, BMI, newBMI;
string BMI_description;
char name[maxUser][50];
char description_BMI[7][50]={"severely underweight","underweight","normal","overweight","obese","clinically obese","morbidly obese"};
float userDetail[maxUser][2];
int playNum;
void intro();
void menu();
void inputhw();
void formula();
void category();
void desc();
void healthy();
void table();
void ask();
//void credit();
void AllUsers();
int main()
{ system("color 5a");
intro();
menu();
system ("pause");
return 0;
}
void intro()
{
int x;
cout<< "\n ----BMI.CALCULATOR----"<< endl;
cout << "\n\nEnter your name: ";
cin >> name[++playNum];
cout << "\a\a";
system("cls");
}
void menu()
{
string opt;
system("cls");
cout << "\t\t\tM.E.N.U\n\n"<< endl;
cout <<"[1]: Calculate your BMI."<< endl;
cout <<"[2]: Show BMI table."<< endl;
// cout <<"[3]: View credits." << endl;
cout <<"[4]: View all users." << endl;
cout <<"[5]: Logout." << endl;
cout << name[playNum] << ", please enter your option: ";
do
{
cin >> opt;
try
{
if(opt.length() > 1 || opt[0] < '1' || opt[0] > '5')
throw opt;
}
catch(string opt)
{
cout << opt << " is invalid option. Please re-enter: ";
}
}
while(opt.length() > 1 || opt[0] < '1' || opt[0] > '5');
cout << "\a\a\a";
system("cls");
switch(opt[0])
{
case '1' : inputhw();break;
case '2' : table();break;
//case '3' : credit();break;
case '4' : AllUsers();break;
default : main();
}
}
void inputhw()
{
cout << "Input your weight (in kg): ";
do
{
cin >> w;
if (w<0 || w>=600) // must not exceed 600 because the weightest man in the world is 555kg only)
cout << "Invalid weight. " << name[playNum] << ", please enter your weight again (in kg): ";
}
while(w<0 || w>=600);
cout << "Input your height (in meter): ";
do
{
cin >> h;
if (h<0 || h>3) // must not exceed 3 because the tallest man in theworld is 2.72)
cout << "Invalid height. " << name[playNum] << ", please enter your height again (in meter): ";
}
while(h<0 || h>3);
BMI=w/pow(h,2);
cout << "\a\a\a";
system("cls");
category();
}
void formula()
{
newBMI=healthyw/pow(h,2);
}
void category()
{
char ans;
userDetail[playNum][0] = BMI;
if (BMI < 16.5)
userDetail[playNum][1] = 0;
else if (BMI >= 16.5 && BMI < 18.5)
userDetail[playNum][1] = 1;
else if (BMI >= 18.5 && BMI < 25)
userDetail[playNum][1] = 2;
else if (BMI >= 25 && BMI <= 30)
userDetail[playNum][1] = 3;
else if (BMI > 30 && BMI <= 35)
userDetail[playNum][1] = 4;
else if (BMI > 35 && BMI <= 40)
userDetail[playNum][1] = 5;
else
userDetail[playNum][1] = 6;
BMI_description = description_BMI[int(userDetail[playNum][1])];
cout << fixed << setprecision(2) << name[playNum] <<", you are " << BMI_description << "\nYour BMI is "<< BMI << "." << endl;
desc();
healthy();
ask();
}
void healthy()
{
int x;
healthyw=w;
if (BMI<18.5)
{
do
{
healthyw++;
formula();
}
while(newBMI<18.5);
cout<<"\n\nYou should increase your weight becoming at least:\n"<<int(healthyw)<<"kg"<<endl;
}
else if (BMI>=25)
{
do
{
healthyw--;
formula();
}
while(newBMI>=25);
cout<<"\n\nYou should decrease your weight becoming at least:\n"<<int(healthyw)<<"kg"<<endl;
}
}
void table()
{
cout <<" THE BMI TABLE"<< endl;
cout <<" _____________________________________________________________"<<endl;
cout <<"| BMI | Rating | Waist Size |"<<endl;
cout <<"|_________|________________|__________________________________|"<<endl;
cout <<"| | | < or = to | > or = to |"<<endl;
cout <<"| | | 40 in. (men) or | 40 in. (men) or|"<<endl;
cout <<"| | | 35 in. (women) | 35 in. (women) |"<<endl;
cout <<"| | | | |"<<endl;
cout <<"| | | | |"<<endl;
cout <<"| <=18.5 | Underweight | -- | N/A |"<<endl;
cout <<"|18.5-24.9| Normal Weight | -- | N/A |"<<endl;
cout <<"|25.0-25.9| Overweight | Increased | High |"<<endl;
cout <<"|30.0-34.9| Obese | High | Very High |"<<endl;
cout <<"|35.0-39.9| Obese | Very High | Very High |"<<endl;
cout <<"| >=40 | Extremely Obese| Extremely High | Extremely High|"<<endl;
cout <<"|_________|________________|_________________|________________|"<<endl;
ask();
}
void desc()
{
if (BMI <= 18.5)
{
cout << "\n\nBMI is equal to or less than 18.5 (Underweight)\n";
cout << "_________________________________________________" << endl;
cout << "\nA lean BMI can indicate that your weight maybe too low. You should consult your physician to determine if you should gain weight,aslow body mass can decrease your body's immune system, which could lead to ilness."<< endl;
}
else if (BMI>=18.5 && BMI<=24.9)
{
cout << "\n\nBMI is between 18.5 and 24.9 (Normal)\n";
cout << "_________________________________________________" << endl;
cout << "People whose BMI is within 18.5 to 24.9 possess the ideal amount of body weight, associated with living longest, the lowest incidenceof serious ilness, as well as being perceived as more physically attractive than people with BMI in higher or lower ranges."<<endl;
}
else if (BMI>=25 && BMI<=29.9)
{
cout << "\n\nBMI is between 25 and 29.9 (Overweight)\n";
cout << "_________________________________________________" << endl;
cout << "People falling in this BMI range are considered overweightand would benefit from finding healthy ways to lower their weight, such asdiet and exercise. Individuals who fall in this range are at increased risk for a variety of ilnesses."<< endl;
}
else if (BMI>=30)
{
cout << "\n\nBMI is over 30 (Obese)\n";
cout << "_________________________________________________" << endl;
cout << "Individuals with a BMI over 30 are in a physically unhealthy condition, which puts them at risk for serious ilnesses such as heart disease, diabetes, high blood pressure, gall bladder disease, and some cancers.These people would benefit greatly by modifying their lifestyle."<<endl;
}
}
void ask()
{
char ans;
int x;
cout << "\n\n" << name[playNum] <<", back to Menu? (Y:yes N:no): ";
do
{
cin >> ans;
if(ans=='Y' || ans=='y')
{
cout << "\a";
menu();
}
else if (ans=='N' || ans=='n')
{
cout << "\a";
system("cls");
cout << "Goodbye, " << name[playNum] << "!\n\n\n" << endl;
break;
}
else
cout << "Invalid option. Please reenter. Back to menu? (Y/N): ";
}
while (ans!='y' && ans!='Y' && ans!='N' && ans!='n');
}
void AllUsers()
{
int i;
system("cls");
cout << "All users that used this program :\n\nNo.\tName\t\tBMI\tDescription\n===\t====\t\t===\t===========\n";
for(i=1;i<=playNum;i++)
cout << i << ".\t" << name
<< "\t\t" << userDetail[0] << "\t"<< description_BMI[int(userDetail[1])] << endl;
cout << "\n\n";
system("pause");
menu();
}