1. NAMES: Use descriptive variable names.
2. Whitespace: Organize your code to be readable.
3. Error handling: Do it first, not second. Make sure unrecoverable errors actually stop the program from continuing.
4. Don't use shortcuts when talking to people. (Example, use "meters", not "M".)
5. Don't add useless widgets/timers/etc. People hate that.
5. You may also wish to work on the visual output of your code. For example, most people only have 80 columns or less of output on the console display. Use "\n" liberally. Avoid
endl
when no force-refresh is needed.
Here is some minor revision that may help.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include <iostream>
using namespace std;
int main()
{
constexpr int min_birth_year=1990;
int birth_year;
int age;
double weight;
double height;
cout << "Please key in your year of birth: ";
cin >> birth_year;
if (birth_year<min_birth_year)
{
cout<<"Sorry, you have to be born from 1990 or onwards to join this experiment.\n";
return 0;
}
cout<<"Great! You are suitable to join this experiment.\n";
cout<<"Before we proceed, how old are you? ";
cin >> age;
if (age<18)
{
cout<<"Sorry, you have to be minimally 18 years old to participate in this experiment.\n";
return 0;
}
cout<<"Perfect! Just one more question to go"<<endl;
cout<<"Please key in your height in meters: ";
cin>>height;
cout<<"Please key in your weight in kilograms: ";
cin>>weight;
double BMI=weight/(height*height);
cout<<"Your BMI is "<<BMI<<endl;
if (BMI<30)
{
cout<<"You have been sucessfully shortlisted for this experiment!\n"
"Our staff will be in touch soon\n";
}
else
{
cout<<"Unfortunately, your BMI is not at the required level.\n"
"You are not suitable for this experiment.\n"
"Thank you for your interest\n";
}
}
|
Overall, it is a good start. Hope this helps.