plzzz help tell what's wrong with my program the value of x is not performed

#include <iostream>
using namespace std;

void main()
{
float height, weight, age, x;
char gender;


cout << "Enter your gender (F or M): ";
do
{
cin >> gender;

switch (gender)
{
case 'F':
case 'f':
x = 655.1 + (9.563 * weight) + (1.850 * height) - (4.676 * age);
break;
case'M':
case 'm':
x = 66.5 + (13.75 * weight) + (5.003 * height) - (6.775 * age);
break;
default:
cout <<" Invalid entry try again: " <<endl;
break;
}
}while ((gender != 'm' || gender != 'M')&& (gender!= 'f' || gender != 'F'));

cout << x <<endl;
}
Last edited on
You are having a void main function! How old is your compiler and does not complain about this?

Anyway you have used your conditions wrong (boolean algebra should be inversed when a part is inverted). This means
A==B || A==C is equal to A!=B && A!=C
The correct is:
while ((gender != 'm') && (gender != 'M') && (gender!= 'f' && gender != 'F'));
Topic archived. No new replies allowed.