VisualDeveloper
Member
In my simple program (console application) below, I am requesting two integer values and then simply using the AddNumbers() function to return the result.
However, the lines of code "Num1 = Console.ReadLine();" and ""Num2 = Console.ReadLine();" produce a build error reporting that it cannot implicitly convert type string to int.
Thanks in advance...
Shuaib
However, the lines of code "Num1 = Console.ReadLine();" and ""Num2 = Console.ReadLine();" produce a build error reporting that it cannot implicitly convert type string to int.
C#:
using System;
namespace Calculator
{
class CCalculator
{
[STAThread]
static void Main(string[] args)
{
//local variables
int Num1;
int Num2;
//welcome message
Console.WriteLine("Welcome to Calculator 1.0");
//request first number
Console.Write("Number 1: ");
Num1 = Console.ReadLine();
//request second number
Console.Write("Number 2: ");
Num2 = Console.ReadLine();
//display result
Console.WriteLine("Total: " + AddNumbers(Num1, Num2));
//finish
Console.WriteLine("Press any key to continue...");
Console.Read();
}
static int AddNumbers(int Number1, int Number2)
{
//add numbers and return result
return (Number1 + Number2);
}
}
}
Shuaib
Last edited by a moderator: