프로젝트의 방향은 다음과 같은 상태 : ". 활동 수준, 입력이 유효하지 않은 경우, 메시지를 인쇄하고 당신은 그들이 앉아있는 것을 가정하는 사용자에게"잘못된/잘못된 입력을 입력하면 어떻게 기본값을 설정할 수 있습니까?
다음
현재 코드입니다, 사용자가 SA 또는 sa로 입력 할 수있는 "Sedentary"
으로 기본 설정하려고합니다. 잘못된 입력에 대한 기본값은 프로그램이 기본적으로 좌식으로 설정되어 있다고 가정하고 올바른 방향에 있는지 여부에 대해 조금 혼란스러워합니다.
else if (gender == 'F' || gender == 'f') {
cout << "Please enter your Height in inches. (You may include a decimal) ";
cin >> height;
cout << "Please enter your Weight in pounds as a whole number. ";
cin >> weight;
cout << "Please enter your Age in years. ";
cin >> age;
cout << endl;
if (activity_level = 'SA' || activity_level = 'sa' || activity_level = 'LA' || activity_level = 'la' ||
activity_level = 'MA' || activity_level = 'ma' || activity_level = 'VA' || activity_level = 'va') {
cout << "Please enter your activity level." << endl << endl;
cout << "You may enter one of the following choices." << endl << endl;
cout << "Sedentary (Little or no exercise) \"SA\" or \"sa\" " << endl;
cout << "Lightly Active (Light exercise/sports 1-3 days a week) \"LA\" or \"la\" " << endl;
cout << "Moderately Active (Moderate exercise/sports 3-5 days a week) \"MA\" or \"ma\" " << endl;
cout << "Very Active (Hard exercise/sports 6-7 days a week) \"VA\" or \"va\" " << endl << endl;
cout << "Enter your activity level now. ";
cin >> activity_level;
cout << endl;
}
// Output for the message to defualt to Sedentary if you do not select activity level throught he proper input.
else {
activity_level =
cout << "I'm sorry I did not recogonize that activity level. We will assume a sedentary amount of exercise. "
}
}
기본적으로 내가하고있는 일이 무엇인지 궁금합니다. else if
진술서 내에서 또 다른 if 문을 사용하면 문제가 해결되며, 현재 설정 한 방식으로 필요한 결과가 나오는지 궁금합니다.
'activity_level = 'SA'는 비교가 아닌 'activity_level'에 * 할당 *을합니다. 'activity_level == "SA"'는 비교 일 것입니다. –
사용자가 입력하기 전에 activity_level을 확인하는 이유는 무엇입니까? –
좋은 점, 나는 그것을 게시 한 후에 적어도 실수를 보았습니다. – user2072795