Simple addition not working in C#

-2

I'm very new to c# and was trying to make a simple program to add 3 numbers, I'm not sure why it is not working here is the code and the error.

int Value;
int Number;
int Thing;

Console.WriteLine("Please State the First Number");
Value = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please State the Second Number");
Number = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please State the Third Number");
Thing = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("{1}+{2}+{3} = {4}", Value + Number + Thing);

Console.ReadLine();

error

'ConsoleApp4.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled. 'ConsoleApp4.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'c:\users\cex\documents\visual studio 2017\Projects\ConsoleApp4\ConsoleApp4\bin\Debug\ConsoleApp4.exe'. Symbols loaded. The program '[13144] ConsoleApp4.exe' has exited with code -1073741510 (0xc000013a).

c#
.net
asked on Stack Overflow Sep 17, 2017 by Fred Enator • edited Sep 17, 2017 by Gary

2 Answers

2

As already pointed out in the comments Console.WriteLine expect four parameters for formatting string, but you provide only one - sum of values Value + Number + Thing

With string interpolation you will never face this kind of errors

Console.WriteLine($"{Value} + {Number} + {Thing} = {Value + Number + Thing}");
answered on Stack Overflow Sep 17, 2017 by Fabio
1

Write this instead:

Console.WriteLine("{0}+{1}+{2} = {3}", Value, Number, Thing, Value + Number + Thing);
answered on Stack Overflow Sep 17, 2017 by eocron

User contributions licensed under CC BY-SA 3.0