Critique for my program

Hi everyone. Just started learning C++ a few days back. Wrote this on my IDE on android for some practice on the go. Could you please provide any comments or critique? Much appreciated!

#include <iostream>
using namespace std;

int main()
{ int a;
int min=1990;
int num=5;
double w; //decimel point for weight
double h; //decimel point fot height
cout << "Please key in your year of birth \n";
cin >> a;
if (a>=min) { cout<<"Great! You are suitable to join this experiment"<<endl;
cout<<"Before we proceed, how old are you?"<<endl;}
else {cout<<"Sorry, you have to be born from 1990 or onwards to join this experiment";}
cin >> a; //asking for age
if (a>=18) { cout<<"Perfect! Just one more question to go"<<endl;}
else {cout<<"Sorry, you have to be minimally 18 years old to participate in this experiment";}
while (num>0) {cout<<"Loading BMI Calculator in "<<num<<endl;num--;}
cout<<"Please key in your height in M"<<endl;
cin>>h;
cout<<"Please key in your weight in KG"<<endl;
cin>>w;
int BMI=w/(h*h); //BMI formula inserted after user input to prevent error and garbage output
cout<<"Your BMI is "<<BMI<<endl;
if (BMI<30) {cout<<"You have been sucessfully shortlisted for this experiment! Our staff will be in touch soon";}
else {cout<<"Unfortunately, your BMI is not at the required level. You are not suitable for this experiment. Thank you for your interest";}
}
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.
Thank you! Will improve!
Topic archived. No new replies allowed.