これで、年齢、体重、身長、性別を問うプログラムがあります。それに応じて、if文を使用してBMRを計算し、if文を使用してDaily Calorie Intakeを計算します。 (DCI)DCIを表示した後、私はWHILEループが必要です。ユーザーはカロリーの量を入力するように求め、それをDCIから減算して残りのカロリーに変えます。助けが必要なコードは一番下にあります。私は、ユーザーが入力した数値を変数にする必要はないと言われましたが、DCIから直接減算することで、残りのカロリーになります。while変数からユーザー入力を引くループ
using System;
namespace Shaft_Lab4
{
class MainClass
{
public static void Main (string[] args)
{
int weight, height, age, gender;
double exerciseFactor;
double DCI = 0;
Console.Write("Enter your age in years ");
age = Convert.ToInt32 (Console.ReadLine());
Console.WriteLine ("Enter your weight in pounds ");
weight = Convert.ToInt32 (Console.ReadLine());
Console.WriteLine ("Enter your height in inches ");
height = Convert.ToInt32 (Console.ReadLine());
Console.WriteLine ("Gender? Enter male/female (1 for Male, 2 for Female) ");
gender= Convert.ToInt32 (Console.ReadLine());
Console.WriteLine("To calculate your daily calories allowed, please select your level of exercise activity");
// exercise intensity levels
Console.WriteLine("1. You don't exercise"); // bmr x 1.2
Console.WriteLine("2. You engage in light exercise one to three days a week"); // bmr x 1.375
Console.WriteLine("3. You exercise moderately three to five times a week"); // bmr x 1.55
Console.WriteLine("4. You exercise intensely six to seven days a week"); // bmr x 1.725
Console.WriteLine("5. you exercise intensely six to seven days a week and have a physically active job"); // bmr x 1.9
exerciseFactor = Convert.ToDouble (Console.ReadLine());
// MALE if statements
if (gender == 1)
{
Console.WriteLine ("Age: " + age);
Console.WriteLine ("Height: " + height);
Console.WriteLine ("Weight: " + weight);
Console.WriteLine ("Gender: Male");
double maleBMR = (66 + (6.23 * weight) + (12.7 * height) - (6.8* age));
Console.WriteLine ("Your BMR is: " + maleBMR);
if (exerciseFactor == 1) {
DCI = maleBMR * 1.2;
Console.WriteLine ("Your daily calories allowed is " + DCI);
}
if (exerciseFactor == 2) {
DCI = maleBMR * 1.375;
Console.WriteLine ("Your daily calories allowed is " + DCI);
}
if (exerciseFactor == 3) {
DCI = maleBMR * 1.55;
Console.WriteLine ("Your daily calories allowed is " + DCI);
}
if (exerciseFactor == 4) {
DCI = maleBMR * 1.725;
Console.WriteLine ("Your daily calories allowed is " + DCI);
}
if (exerciseFactor == 5) {
DCI = maleBMR * 1.9;
Console.WriteLine ("Your daily calories allowed is " + DCI);
}
// FEMALE if statements
}
if (gender == 2)
{
Console.WriteLine ("Age: " + age);
Console.WriteLine ("Height: " + height);
Console.WriteLine ("Weight: " + weight);
Console.WriteLine ("Gender: Female");
double femaleBMR = (655 + (4.35 * weight) + (4.7 * height) - (4.7 * age));
Console.WriteLine ("Your BMR is: " + femaleBMR);
if (exerciseFactor == 1) {
DCI = femaleBMR * 1.2;
Console.WriteLine ("Your daily calories allowed is " + DCI);
}
if (exerciseFactor == 2) {
DCI = femaleBMR * 1.375;
Console.WriteLine ("Your daily calories allowed is " + DCI);
}
if (exerciseFactor == 3) {
DCI = femaleBMR * 1.55;
Console.WriteLine ("Your daily calories allowed is " + DCI);
}
if (exerciseFactor == 4) {
DCI = femaleBMR * 1.725;
Console.WriteLine ("Your daily calories allowed is " + DCI);
}
if (exerciseFactor == 5) {
DCI = femaleBMR * 1.9;
Console.WriteLine ("Your daily calories allowed is " + DCI);
}
}
//THIS IS WHERE I NEED HELP
string response = "YES";
while (response == "YES") {
Console.WriteLine ("Enter the amount of calories consumed: ");
Convert.ToInt32 (Console.ReadLine());
Console.WriteLine ("Do you want to continue? (YES/NO)");
}
}
}
}
は非常に役に立ちますが、コンソール読み取り整数? –
@JasonShaft - 'ConsoleReadInteger'は私の答えのコードにあります。 – Enigmativity
ええ、それは動作しません。いいえ、私はプログラムを稼働させました、私がする必要があったのは2つの簡単な言葉を切り替えることでした。 –