Hi I'm still a beginner at programming and having to do a Biological Age calculator program with if else if statements. I've done the bulk of my work but need help understanding why I'm getting certain errors and some help with how to calculate what I need.
I've added comments about the errors in my code. I wasn't able to post all of my code because it made my post over 9000 characters. But most of my code is using if else if statements and multiple choice questions to add numbers amounts based on each answer to calculate biological age.
//Biological Age Calculator
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
//The main error I'm seeing when I try to build is warning C4244 conversion from double to int. Possible loss of data. This occurs on many lines.
int ageWork = 0; //This is supposed to be set to zero
char ch, gender; //One of my errors when I try to build it says uninitialized local variable ch.
double chronAge, bioAge, answer;
string name;
ch = toupper(ch); //I need to use this for when the user enter a letter it's converted to a capital letter but I don't know if I'm using it properly.
cout << "Welcome to Programmer's Biological Age Calculator" << endl;
cout << "Enter the subject's age: " << endl;
cin >> chronAge;
cout << "Enter your gender (M or F): " << endl;
cin >> gender;
cout << "Enter your first name: " << endl;
cin >> name;
cout << endl;
cout << "What's your body mass index (BMI)?"
<< "A. 0 to 17"
<< "B. 18 to 21"
<< "C. 22 to 24"
<< "D. 25 to 30"
<< "E. >30\n\n";
cin >> answer;
//This is where the first if else if statement starts and I'm not sure if I'm doing this completely right. I have to add numbers to ageWork in order to get the calculations at the end and get bioAge.
if (answer = 'A')
ageWork = answer - 7; //Calculations by adding amount to ageWork. I believe I'm doing this wrong but I'm not entirely sure how to approach this.
elseif (answer = 'B')
ageWork = answer - 7;
elseif (answer = 'C')
ageWork = answer + 4;
elseif (answer = 'D')
ageWork = answer + 10;
elseif (answer = 'E')
else
{
cout << "Please enter a letter" << endl; //Trailing else to assure user enters a letter.
}
//Biological age and chronological age calculations
ageWork = ageWork / 10; //ageWork is set to 0 and every answer the user enters adds a number to ageWork at the end.
bioAge = ageWork + chronAge;
cout << "CSDE Biological Age Calculator Report for: " << name << endl;
cout << endl;
cout << "Chronological Age: " << chronAge << endl;
cout << "Biological Age" << bioAge << endl;
cout << endl;
cout << "Thank you for using programmer's Biological Age Calculator" << endl;
system("cls");
return 0;
}
Okay so I fixed the C4244 errors by removing answer from the (ageWork = ) lines. Whenever I'm doing this none of the numbers in the if else if statements are being added to ageWork. So I know I'm doing it wrong but I don't know how to fix it.
What do you want as body max index?
Do you want a number or a character ('A' or 'B' or 'C'...)?
I would answer with a character to that question, but then you try to apply formulas to that answer...
I wasn't able to post the entirety of the multiple choice questions in my question here because it went over 9,000 characters and told me I can't post it. So that's just question 1 but I have 12 questions in total.
The multiple choice questions are where the user inputs their answer 'A' 'B' 'C' etc. and based on the user input an amount is added to the variable ageWork which is set to 0 so I can calculate Biological age at the end of the program.
Each answer has a numerical value to it. For example, if the user enters 'A' for question 1 it subtracts 7 from ageWork. While if they enter 'C' it adds 4 to ageWork.
After all the questions are answered ageWork is divided by 10 to get the bioAge.
I'm not really sure how to accomplish this with if else if statements but that's what I have to use. I also may approaching this in the wrong way. :/