Monday
April 27, 2015

Homework Help: C++ if else problem, please look

Posted by sonnytsn on Monday, January 24, 2011 at 5:50pm.

It compiles but it doesn't work. can you tell me what i did wrong?

//Sonny Hinh, variable program, assignment 2
#include <iostream>
using namespace std;

int main ()
{ char gender;
int age, bmi, dose1, dose2;
double dose3, dose4;
dose1 = bmi * 2;
dose2 = bmi * 2 + 13;
dose3 = bmi * 2 * .95;
dose4 = bmi * 2 + 13 * .95;
cout << "Enter age: ";
cin >> age;
cout << "Enter BMI: ";
cin >> bmi;
cout << "Enter sex (M or F): ";
cin >> gender;
if (gender == 'M')
{ if (age < 12)
{ cout << "\nDose is: " << dose1 << " units" << endl;
}
else
{ cout << "\nDose is: " << dose2 << " units" << endl;
}
}
else
{ if (age < 12)
{ cout << "\nDose is: " << dose3 << " units" << endl;
}
else
{ cout << "\nDose is: " << dose4 << " units" << endl;
}
}
system("PAUSE");
return 0;
}

Answer this Question

First Name:
School Subject:
Answer:

Related Questions

Members