Pergunta

I am trying to get the sum of two numbers, but it is not displaying correctly. Here is the code:

int number1 = 1;
int number2 = 3;

Console.Write("The sum of " number1 "and" number2 "is" total ".");
Foi útil?

Solução 2

try this:

Console.Write("The sum of " + number1 + " and " + number2 + " is " + total +".");

You need the + operator to concatenate string together.

Outras dicas

Try this:

Console.Write("The sum of {0} and {1} is {2}.", number1, number2, total); 
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top