pls help , I can't figure out my prob... especially for the char part

#include <iostream>
using namespace std;

int main(void)

{
int age; int weight; char smoker;



cout << "Want to become an astronaut? \n";

cout << "What is your age \n";
cin >> age;



cout << "What is your weight (kg)? \n";
cin >> weight;

cout << "Are you a smoker? (enter y if yes and n if no) \n";
cin >> smoker;


if ((age >= 35 && age <= 46) && (weight >= 50 && weight <= 80) && ( smoker == y ))
cout << "We may consider.";

else
cout << "Sorry we cannot accept you as an astronaut.";

return 0;
}
Last edited on
Hi,
( smoker == y )


It should be :
( smoker == 'y' )

You might want to check if an user enters a (Y) in addition to checking if (y) is pressed :
( toupper(smoker) == 'Y' )

Since an astronaut is often guaranteed not to smoke, this line should be correct and ideal :
( toupper(smoker) == 'N' )

So :
if ((age >= 35 && age <= 46) && (weight >= 50 && weight <= 80) && ( toupper(smoker) == 'N' ))
In order to be able to use the function toupper() remember to include <stdio.h>
Does that help you? :)
Thx a lot... It works. I'm kinda new in programming, so this kind of small error may be made
You are good to go :)
Topic archived. No new replies allowed.