do you mean if(avg3 == "c")
instead of if (avg3 = "c")
(avg3 = "c")
you are assigning "c"
to avg3
which is of type int
which explains " Cannot implicitly convert type 'string' to 'int'".
String avg3Str = Console.ReadLine();
if (avg3Str.equals("c")){
Console.WriteLine("Ok, Lets calculate!");
average = (avg1 + avg2)/numavg;
Console.WriteLine("The average is " + average + ".");
}
else {
avg3 = int.Parse(avg3Str);
Console.WriteLine("Perfect! please type the next number,or 'c' for avg to the last 3 numbers.");
String avg4Str = Console.ReadLine();
if (avg4Str.equals("c") ){
Console.WriteLine("Ok, Lets calculate!");
average1 = (avg1 + avg2 + avg3)/numavg;
Console.WriteLine("The average is " + average1 + ".");
}
else
{
avg4 = int.Parse(avg4Str);
Console.WriteLine("Ok, Lets calculate!");
average1 = (avg1 + avg2 + avg3 + avg4)/numavg;
Console.WriteLine("The average is " + average1 + ".");
}
}
1
solved Int and string together [closed]