Sorry during reformatting i erased it. i can make this easy by asking this. i want to someone to put in something like "ice cream" and later in the program i say you can eat 8 " ics cream"s or whatever the user puts in.
The program takes the users age, height, weight and calculates BMR(so equation to keep weight stable). The program needs to be edited so that the user can add some different variable and get an answer. The only problem i'm having is getting the program to store the users food choice as a word instead of a number.
cout << "Enter the letter association with your activity level: ";
cin >> ExerciseType;
cout << "What type of food do you want to eat? Please use _ between words to create a single word.";
std::getline(std::cin, food_choice);
cin >> leaves a newline in the buffer after you hit enter. By default getline reads until a newline is found so you should remove the extra newline from the buffer before using getline. You can use std::cin.ignore();, std::cin.ignore(1024, '\n');, or std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); I prefer the last option.\
#include <iostream>
#include <string>
int main()
{
int Height;
int Weight;
int Age;
int Calories; //The variables that will be used in the program.
double BMR;
char Gender, ExerciseType;
std::string food_choice;
std::cout.setf(ios::fixed);
std::cout.setf(ios::showpoint);
std::cout.precision(0);
std::cout << "Please provide your basic information" << endl; //Collecting of inputs for later phase of program.
std::cout << "male or female (m or f)? ";
std::cin >> Gender;
std::cout << "age in years? ";
std::cin >> Age;
std::cout << "weight in pounds? ";
std::cin >> Weight;
std::cout << "height in inches? ";std::cin >> Height;
std::cout << "How active are you?" << std::endl;
std::cout << "s - sedentary" << std::endl;
std::cout << "c - casual exerciser--exercise occasionally" << std::endl;
std::cout << "a - active exerciser--exercise 3-4 days per week" << std::endl;
std::cout << "d - devoted exerciser--exercise every day" << std::endl;
std::cout << "Enter the letter association with your activity level: ";
std::cin >> ExerciseType;
std::cout << "What type of food do you want to eat? Please use _ between words to create a single word.";
std::cin.ignore(1024, '\n'); //ignore newline and anything else possibly left in buffer
std::getline(std::cin, food_choice);
std::cout << "How many calories per item? ";
std::cin >> Calories;
if (Age >= 65) // Statements that build only once conditions are met and fufills the program.
{
BMR = 1.375 * (655 + (4.3 * Weight) + (4.7 * Height) - (4.7 * Age));
}
elseif (Gender == 'f' || Gender == 'F')
{
BMR = 1.375 * (655 + (4.3 * Weight) + (4.7 * Height) - (4.7 * Age));
}
elseif (Gender =='m' || Gender == 'M');
{
BMR = 1.375 * (66 + (6.3 * Weight) + (12.9 * Height) - (6.8 * Age));
}
switch(ExerciseType) // Calculations for the differing case
{
case's' :
BMR = (BMR - (BMR * .05));
std::cout << "BMR = " << BMR << std::endl;
BMR = (BMR / Calories);
std::cout << "number of " << food_choice << " eaten = " << BMR;
break;
case'c' :
BMR = ((BMR * .30) + BMR);
std::cout << "BMR = " << BMR << std::endl;
BMR = (BMR / Calories);
std::cout << "number of " << food_choice << " eaten = " << BMR;
break;
case'a' :
BMR = ((BMR * .40) + BMR);
std::cout << "BMR = " << BMR << std::endl;
BMR = (BMR / Calories);
std::cout << "number of " << food_choice << " eaten = " << BMR;
break;
case'd' :
BMR = ((BMR * .50) + BMR);
std::cout << "BMR = " << BMR << std::endl;
BMR = (BMR / Calories);
std::cout << "number of " << food_choice << " eaten = " << BMR;
default :
std::cout << "Invalid Choice" << std::endl;
return 0;
}
}
You also have multiple naming conventions most of them start with uppercase and one has underscores with lowercase. Though that is probably from copying LB's variable :P
Keep in mind most IDE's will indent it for you automatically when you hit enter.
Hey;
if getline() is followed by an earlier cin statement you need to flush out the endof line char from the previous feed.
in your code Before calling getline use the below line
cin.ignore(numeric_limits<streamsize>::max(), '\n');