I have created a simple program in which the user have to answer some question and see in the end how much credit he had got. The answer should be Yes or No. And recently (after I finished my program and it worked fine), I have noticed that there are amethod ToUpper()
. So I wanted to enter it in my program. I have used if statement for useranswer Yes or No and since I can't write like that: if (answer1 == yes), I have stored "Yes" in a string called s. And it worked, but I can't use now s.ToUpper
. So I had to change from if statement to switch statement and everything goes alright except that unassigned local variable which store how much each question have credit. The wrong is in g = i1 + i2 + i3 + i4 + i5
. Those "i" are unassingned value. Can anyone help me? And if there is a way to use ToUpper with if statement, I don't mind to use it again. Here's my code:
int p = 0;
int i1;
int i2;
int i3;
int i4;
int i5;
int g;
int qu1 = 10;
int qu2 = 20;
int qu3 = 20;
int qu4 = 25;
int qu5 = 25;
Console.WriteLine("Calculating the probability of being diabete patient, please answer by yes or no");
Console.Write("What is your name ? \n");
string username = Console.ReadLine();
Console.Write("Do you smoke ? \n");
string answer1 = Console.ReadLine();
switch(answer1.ToUpper())
{
case "YES":
i1 = p + qu1;
break;
case "NO":
i1 = p + 0;
break;
}
Console.Write("do one of your parents have diabetes ? \n");
string answer2 = Console.ReadLine();
switch (answer2.ToUpper())
{
case "YES":
i2 = p + qu2;
break;
case "NO":
i2 = p + 0;
break;
}
Console.Write("do u eat ? \n");
string answer3 = Console.ReadLine();
switch (answer3.ToUpper())
{
case "YES":
i3 = p + qu3;
break;
case "NO":
i3 = p + 0;
break;
}
Console.Write("do u drink ? \n");
string answer4 = Console.ReadLine();
switch (answer4.ToUpper())
{
case "YES":
i4 = p + qu4;
break;
case "NO":
i4 = p + 0;
break;
}
Console.Write("do u speak ? \n");
string answer5 = Console.ReadLine();
switch (answer5.ToUpper())
{
case "YES":
i5 = p + qu5;
break;
case "NO":
i5 = p + 0;
break;
}
g = i1 + i2 + i3 + i4 + i5;
Console.WriteLine(username + "," + "your percentage of gtting diabetes is {0}", g + "%");
if (g == 100)
{
Console.WriteLine("You need to take care, and try to follow a healthy lifestyle and stop smoking");
}
if (g >= 50)
{
Console.WriteLine("Pay attention, you are no longer in the safe zone");
}
if (g <= 50)
{
Console.WriteLine("You are in the safe zone, but you can decrease the percentage if you take a little bit care of your health");
}
Console.ReadKey();